WPF MediaElement with rounded corner
Asked Answered
R

2

7

In WPF, i wish to create rounded corner for my movie, but the movie actually will overlap the border and i get a normal rectangle box that load my movie. Any idea how to solve this issue? enter image description here

<Border BorderBrush="#FF000000" BorderThickness="1,1,1,1" CornerRadius="20,20,20,20">
    <Grid>
        <MediaElement x:Name="movieLoader" HorizontalAlignment="Left" Height="128" VerticalAlignment="Top" Width="236" Source="../video/empty.mp4"/>
    </Grid>
</Border>
Rocketeer answered 30/8, 2013 at 12:49 Comment(0)
S
6

Try this:

<Border x:Name="border" BorderThickness="1" BorderBrush="#FF000000" CornerRadius="20" Padding="1"
        HorizontalAlignment="Center" VerticalAlignment="Center">
    <Grid>
        <Border Name="mask" Background="White" CornerRadius="{Binding ElementName=border, Path=CornerRadius}"/>
        <Grid>
            <Grid.OpacityMask>
                <VisualBrush Visual="{Binding ElementName=mask}"/>
            </Grid.OpacityMask>
            <MediaElement x:Name="movieLoader" HorizontalAlignment="Left" Height="128" 
                          VerticalAlignment="Top" Width="236" Source="../video/empty.mp4"/>
        </Grid>
    </Grid>
</Border>
Scraper answered 31/8, 2013 at 9:10 Comment(0)
E
1

Set ClipToBounds to True.

<Border ClipToBounds="True" BorderBrush="#FF000000" BorderThickness="1"
    CornerRadius="20">
    <Grid>
        <MediaElement x:Name="movieLoader" HorizontalAlignment="Left"
            Height="128" VerticalAlignment="Top" Width="236"
            Source="../video/empty.mp4"/>
    </Grid>
</Border>
Epicenter answered 30/8, 2013 at 15:47 Comment(1)
Still the same, the movie is still in rectangle shape. Any idea?Rocketeer

© 2022 - 2024 — McMap. All rights reserved.