带圆角的WPF MediaElement

时间:2013-08-30 12:49:40

标签: wpf movie

在WPF中,我希望为我的电影创建圆角,但是电影实际上将与边框重叠,我得到一个加载我的电影的普通矩形框。不知道如何解决这个问题? 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>

2 个答案:

答案 0 :(得分:3)

试试这个:

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

答案 1 :(得分:1)

ClipToBounds设为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>