Canvas中的MediaElement不会Strech to Fill

mar*_*yyy 4 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>
Run Code Online (Sandbox Code Playgroud)

但出于某种原因,视频(在这种情况下为1.wmv)不会填满屏幕.为什么?

Jam*_*Hay 5

添加到"画布"的元素将不会相对于"画布"进行调整.它们将是未拉伸的尺寸或已明确设置的尺寸(通过设置宽度,高度等).要获取要拉伸的项目,您需要支持该功能的容器作为网格.

例如:

<Grid>
   <MediaElement Name="lightMovie" Source="C:\knoblauch\lights\1.wmv" Stretch="Fill" />
</Grid>
Run Code Online (Sandbox Code Playgroud)

像你期待的那样工作.