如何在UWP中使UserControl全屏?

时间:2016-07-14 06:26:49

标签: user-controls uwp fullscreen mediaelement

我有Usercontrol(名为MyControl)

   <!-- Upload Media Starts -->
        <div class="row">
            <hr>
            <h3>ADD MORE MEDIA TO COLLECTION</h3>
            <div id="upload_button_group">
                <a href="javascript:void(0)" class="button" id="upload_button">From My Computer</a>
                <a href="javascript:void(0)" class="button button-blue" id="upload_button_URL">From YouTube URL</a>
            </div>
            <form id="upload_form" name="upload_form" method="post" action="media_upload.php" enctype="multipart/form-data">
                <input type="file" id="upload_media" name="upload_media" accept="image/*" style="display:none">
            </form>
            <form id="upload_form_url" name="upload_form_url" method="post" action="media_upload.php"  style="display:none">
                <input class="text-field" name="youtube_url" id="youtube_url" type="text" placeholder="Please enter YouTube URL">
                <a href="javascript:void(0)" class="button" id="upload_button_URL_save">Save</a>
                <a href="javascript:void(0)" class="button button-blue" id="upload_button_URL_cancel">Cancel</a>
            </form>
        </div>
   <!-- Upload Media Ends -->

和MainPage.xaml

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

我想点击&#34; btnFullscreen&#34;制作&#34; MyControl&#34;全屏模式,如你在每个视频播放器中切换全屏模式,在全屏模式下有&#34; btnFullscreen&#34;和&#34;播放器&#34;

对不起,我说英语不太好,非常感谢你!

1 个答案:

答案 0 :(得分:0)

您可以通过以下代码将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。您可以通过本文档的 添加自定义按钮 部分找到一种向视频播放器添加全屏按钮的方法。以下是自定义媒体传输控制的官方示例:XamlCustomMediaTransportControls