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

时间:2016-07-29 07:14:46

标签: 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>

Rendering of the above design

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

VideosMediaElement.IsFullWindow = true;
<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>

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

1 个答案:

答案 0 :(得分:4)

您可以检查实时可视树以在运行时检查您的布局: enter image description here

MediaElement进入FullScreen模式时,FullWindowMediaRoot将托管MeidiaElement,并且您的mediaGrid将不会在此时间内显示。一种方法是@Chris W.说使用TransportControls的{​​{1}},但这在Windows 8.1应用程序中不可用,因为您开发了一个Windows Phone 8.1应用程序,没有这样的问题。

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

MediaElement

由于应用程序在WP8.1上作为全屏模式运行,因此此方法也会使VideosMediaElement.Width = Window.Current.Bounds.Width; VideosMediaElement.Height = Window.Current.Bounds.Height; 看起来像是全屏模式。当您想要“退出全屏模式”时,您只需重置MediaElementHeight属性。