如何在 UWP 中使 UserControl 全屏显示?

How to make UserControl fullscreen in UWP?

我有用户控件(名为 MyControl)

<Grid Background="White">
        <MediaElement Name="Player"></MediaElement>
        <Button Name="btnFullscreen" 
                VerticalAlignment="Bottom" 
                HorizontalAlignment="Center"
                Content="Fullscreen"></Button>
</Grid>

和MainPage.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <local:MyControl></local:MyControl>
</Grid>

我想点击 "btnFullscreen" 使 "MyControl" 全屏,就像您在每个视频播放器中切换全屏模式一样,在全屏模式下有 "btnFullscreen" 和 "Player"

抱歉,我的英语不是很好,非常感谢!

您可以通过以下代码将 MediaElement 控件设置为全屏模式:

private void btnFullscreen_Click(object sender, RoutedEventArgs e)
{
    ApplicationView.GetForCurrentView().TryEnterFullScreenMode();
    Player.IsFullWindow = true;
}

和MyControl.xaml:

<Grid>
    <MediaElement Name="Player"  AreTransportControlsEnabled="True" >
    </MediaElement>
    <Button Name="btnFullscreen" 
            VerticalAlignment="Bottom" 
            HorizontalAlignment="Center"
            Content="Fullscreen" Click="btnFullscreen_Click"></Button>
</Grid>

更新: 如果您想用新的播放器控件(如播放按钮、音量滑块、全屏按钮、滑块等)重新创建视频播放器。我建议您按照本文档的步骤操作:Create custom media transport control. And you can find a way to add fullscreen button to your Video Player by Adding a custom button section of this document. Here is the official sample of custom media transport control: XamlCustomMediaTransportControls.