MediaElement in Canvas doesnt Strech to Fill

4.8k Views Asked by At

I want to view a fullscreen video and thought this works like this:

<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>

but for some reason the video, in this case 1.wmv, doesnt fill up the screen. Why?

1

There are 1 best solutions below

0
On BEST ANSWER

Elements added to a Canvas will not be sized relative to the Canvas. They will be their non stretched size or a size which has been explicitly set (through setting Width, Height, etc). To get items to stretch you need containers that support that functionality suach as a Grid.

For instance:

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

works as you are expecting.