使用 UniformToFill 时,为什么我的媒体元素无法正确调整大小和剪辑?
当我使用 UniformToFill 拉伸时,为什么我的媒体元素无法正确填充屏幕?如果窗口比 mediaElement 宽,则 mediaElement 将在底部剪辑;如果窗口比 mediaElement 高,则 mediaElement 将在右侧剪辑。
<Window x:Class="WpfApplication1.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Preview Window" Height="200" Width="600" WindowStyle="None" Background="Black" ResizeMode="CanMinimize" MouseLeftButtonDown="Window3_MouseLeftButtonDown" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid Focusable="False">
<MediaElement Name="mediaElement2" LoadedBehavior="Manual" MediaOpened="mediaElement2_MediaOpened" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="289,-19,-11,-19" />
<MediaElement Name="mediaElement1" LoadedBehavior="Manual" MediaOpened="mediaElement1_MediaOpened" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="-11,0,289,0"/>
</Grid>
在程序中,我使用这些命令来拉伸它,并使用视觉画笔将这些视频应用到另一个窗口。问题出现在该窗口中,视频/图片剪辑不正确
window3.mediaElement1.Stretch = Stretch.UniformToFill;
window3.mediaElement2.Stretch = Stretch.UniformToFill;
Why don't my media elements fill the screen correctly when I use the UniformToFill stretch? The mediaElement clips at the bottom if the window is wider than the mediaElement, and it clips at the right if the window is taller than the mediaElement.
<Window x:Class="WpfApplication1.Window3"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Preview Window" Height="200" Width="600" WindowStyle="None" Background="Black" ResizeMode="CanMinimize" MouseLeftButtonDown="Window3_MouseLeftButtonDown" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid Focusable="False">
<MediaElement Name="mediaElement2" LoadedBehavior="Manual" MediaOpened="mediaElement2_MediaOpened" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="289,-19,-11,-19" />
<MediaElement Name="mediaElement1" LoadedBehavior="Manual" MediaOpened="mediaElement1_MediaOpened" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="-11,0,289,0"/>
</Grid>
In the program I use these commands to stretch it and use visual brushes to apply these videos to another window. The problem occurs in this window where the video/picture clip incorrectly
window3.mediaElement1.Stretch = Stretch.UniformToFill;
window3.mediaElement2.Stretch = Stretch.UniformToFill;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将 Stretch 属性设置为 Stretch.Uniform 而不是 Stretch.UniformToFill。
如果您想填充整个屏幕而不保持相对尺寸,也可以尝试 Stretch.Fill 来停止剪切。
Try setting the Stretch property to Stretch.Uniform instead of Stretch.UniformToFill.
If you want to fill the whole screen without maintaining relative dimensions, also try Stretch.Fill to stop clipping.