Question

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;
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top