c# - Canvas 中的 MediaElement 不会拉伸(stretch)以填充

标签 c# wpf xaml mediaelement

我想观看全屏视频,我认为它是这样工作的:

<Window x:Class="test.Overlay"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Overlay" Height="300" Width="300" WindowState="Maximized">
<Grid>
    <Canvas Name="lightCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <MediaElement Name="lightMovie" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Source="C:\knoblauch\lights\1.wmv" Stretch="Fill" />
    </Canvas>
</Grid>

但出于某种原因,视频(在本例中为 1.wmv)没有填满屏幕。 为什么?

最佳答案

添加到 Canvas 的元素不会相对于 Canvas 调整大小。它们将是它们的非拉伸(stretch)尺寸或已明确设置的尺寸(通过设置宽度、高度等)。要让项目拉伸(stretch),您需要支持该功能的容器,例如网格。

例如:

<Grid>
   <MediaElement Name="lightMovie" Source="C:\knoblauch\lights\1.wmv" Stretch="Fill" />
</Grid>

如您所愿。

关于c# - Canvas 中的 MediaElement 不会拉伸(stretch)以填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4886850/

相关文章:

c# - WPF 使用异步方法更新 ListBox 中的项目源

wpf - 在 XAML 中设置 WPF ContextMenu 的 PlacementTarget 属性?

c# - 设置鼠标悬停/用户单击按钮的样式

c# - 在 SQLDataReader 上使用

c# - 在 mvc4 上记录和跟踪

c# - 我如何从excel中获取单元格地址

wpf - 与 WPF 中的数学运算绑定(bind)

javascript - 如何在另一个aspx页面中通过URL获取值

c# - RichTextBox 在其中拖放时抛出异常

wpf - 如何在 View 模型中使用第三方控件?