MediaElement in canvas does not work Strech to fill

I want to watch a full screen video and thought it worked as follows:

<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, does not fill the screen. Why?

+4
source share
1 answer

Elements added to the canvas will not be sized relative to the canvas. They will have their unstretched size or the size that was explicitly set (by setting the width, height, etc.). To get elements for stretching, you need containers that support this functionality, like a grid.

For instance:

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

works as you expect.

+5
source

Source: https://habr.com/ru/post/1338258/


All Articles