保持元素显示在全屏UWP应用程序中

Bha*_*ala 8 c# xaml windows-phone-8.1 uwp

下面是我的设计,包含媒体元素,播放,暂停,全窗口和导引头.

<MediaElement x:Name="VideosMediaElement" VerticalAlignment="Top"
              Height="250" Width="355" Margin="0,20,0,0"
              BufferingProgressChanged="VideosMediaElement_BufferingProgressChanged"
              RealTimePlayback="True"
              />
<Grid x:Name="mediaGrid">
    <Border VerticalAlignment="Bottom" Height="60" Background="Black"
            Opacity="0.1">
    </Border>
    <Image x:Name="PlayIcon" Source="Assets/Play-icon.png"
           Height="35" HorizontalAlignment="Left" VerticalAlignment="Bottom"
           Margin="3,0,0,10" Visibility="Collapsed" Tapped="PlayIcon_Tapped">
    </Image>

    <Image x:Name="PauseIcon" Source="Assets/Pause.png"
           Height="35" HorizontalAlignment="Left" VerticalAlignment="Bottom"
           Margin="3,0,0,10" Tapped="PauseIcon_Tapped" Visibility="Visible">
    </Image>

    <TextBlock x:Name="duration" Foreground="White" VerticalAlignment="Bottom"
               Margin="43,0,0,20">
    </TextBlock>

    <ProgressBar x:Name="videoProgressBar" VerticalAlignment="Bottom"
                 Margin="15 0 10 25" Foreground="DarkBlue" Background="Gray"
                 Width="180" Height="10" Minimum="0"
                 Maximum="{Binding Path=NaturalDuration.TimeSpan.TotalSeconds,
                                   Mode=TwoWay, 
                                   ElementName=VideosMediaElement}"
                 Value="{Binding Path=Position.TotalSeconds, Mode=TwoWay,
                                 ElementName=VideosMediaElement}"
                 Tapped="videoProgressBar_Tapped"
                 />

    <TextBlock x:Name="maximumDuration" Foreground="White" Margin="0,0,40,20"
               VerticalAlignment="Bottom" HorizontalAlignment="Right">
    </TextBlock>

    <Image x:Name="ExpandEnabled" Source="Assets/Fullscreen.png"
           Tapped="Zoom_Tapped" Height="35" Margin="0 0 3 10"
           HorizontalAlignment="Right" VerticalAlignment="Bottom">
    </Image>
</Grid>
Run Code Online (Sandbox Code Playgroud)

渲染以上设计

如果我单击右侧的完整窗口图标,视频将显示为带有播放,暂停,搜索者和完整窗口按钮的完整窗口.

VideosMediaElement.IsFullWindow = true;
Run Code Online (Sandbox Code Playgroud)
<MediaElement x:Name="VideosMediaElement" VerticalAlignment="Top"
              Height="300" Width="360"
              BufferingProgressChanged="VideosMediaElement_BufferingProgressChanged"
              AreTransportControlsEnabled="True">
    <MediaElement.TransportControls>
         <MediaTransportControls IsCompact="True" IsZoomButtonVisible="False"
                                 IsZoomEnabled="False"
                                 IsPlaybackRateButtonVisible="True"
                                 IsPlaybackRateEnabled="True"
                                 />
    </MediaElement.TransportControls>
</MediaElement>
Run Code Online (Sandbox Code Playgroud)

视频在完整窗口中播放,但是当我设置IsWindowFull属性时,播放,暂停和搜索器都隐藏了.如何在媒体元素处于完整窗口时显示这些控件?

Gra*_*eng 4

您可以检查实时可视化树来检查运行时的布局: 在此输入图像描述

当aMediaElement进入该FullScreen模式时,FullWindowMediaRoot将主持该MeidiaElement并且您的mediaGrid将不会在此时显示。一种方法是正如@Chris W.所说,使用TransportControlsof MediaElement,但这在Windows 8.1应用程序中不可用,因为您开发了Windows Phone 8.1应用程序,所以不存在这样的问题。

由于 WP8.1 不支持自定义传输控件,因此对于 Windows Phone 8.1 应用程序,您可以手动设置Width应用程序的Height大小MediaElement,例如:

VideosMediaElement.Width = Window.Current.Bounds.Width;
VideosMediaElement.Height = Window.Current.Bounds.Height;
Run Code Online (Sandbox Code Playgroud)

由于该应用程序在 WP8.1 上以全屏模式运行,因此此方法也会使其看起来MediaElement像处于全屏模式。当您想“退出全屏模式”时,只需重置HeightWidth属性即可。