【发布时间】:2016-12-03 19:24:41
【问题描述】:
下面是我的设计,包含媒体元素、播放、暂停、全窗口和搜索器。
<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>
如果我单击右侧的全窗口图标,视频将显示为全窗口,带有播放、暂停、搜索和全窗口按钮。
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 属性时,播放、暂停和搜索器都隐藏了。媒体元素全屏时如何显示这些控件?
【问题讨论】:
-
在这种情况下,为什么不直接使用默认的TransportControls,因为你没有做任何过于自定义的事情,它看起来无论如何都会看起来更干净?
-
感谢@ChrisW。它工作得很好
-
嗨@ChrisW,我在使用默认传输控件时遇到问题。当用户单击最大化按钮时,我想在横向模式下以全窗口显示视频。但是,在那种情况下,没有任何事件被触发。有没有办法得到它?非常感谢您的帮助。谢谢。
-
哪些事件?你的意思是覆盖视频的按钮?
-
嗨@ChrisW,我已经添加了我的代码。在代码中我使用的是 TrasportControls。它在纵向模式下工作正常。但是,我担心的是,当用户单击最大化按钮时,它应该在全窗口中变为横向模式。
标签: c# xaml windows-phone-8.1 uwp