如何在 Windows Phone 8.1 上将媒体元素更改为横向模式下纵向和全屏缩放
本文关键字:模式 横向 缩放 Phone Windows 元素 媒体 | 更新日期: 2023-09-27 17:57:07
当手机以横向模式旋转时,我很难尝试将<mediaelement />
自动更改为全屏。现在,当我点击右下角的按钮时,视频将全屏播放,当我点击它时,它会缩放到全屏,但我不希望这样。在纵向模式下,我正在尝试根据手机屏幕的宽度使<mediaelement />
适合,但我不确定该怎么做,或者我在布局问题上做错了什么。
下面是我在 XAML 中的布局:
MainPage.xaml:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<StackPanel Width="Auto" Height="250" Background="Green" Orientation="Horizontal" VerticalAlignment="Top">
<MediaElement x:Name="media"
Source="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
AutoPlay="True"
AreTransportControlsEnabled="True"
HorizontalAlignment="Center"
VerticalAlignment="Top"
Stretch="UniformToFill"
Width="Auto"
Height="Auto"
/>
</StackPanel>
</Grid>
更新了方向更改的代码:
我调试了此方法,当手机处于横向模式时,它将通过 if 语句,但是当我纵向倾斜手机时,它无法识别任何内容。当手机进入纵向时,我缺少什么来识别纵向事件处理程序?MediaElement 似乎陷入了IsFullWindow = true
,再也不会检查方向更改的事件方法是否变得IsFullWindow = false
。
void MainPage_OrientationChanged(DisplayInformation sender, object args)
{
var orientation = DisplayInformation.GetForCurrentView().CurrentOrientation; // get the current orientation of the display
if (orientation == DisplayOrientations.Landscape || orientation == DisplayOrientations.LandscapeFlipped) // if the orientation is landscape...
{
media.IsFullWindow = true; // puts the media element in full screen while in landscape
}
else //if (orientation == DisplayOrientations.Portrait || orientation == DisplayOrientations.PortraitFlipped)
{
media.IsFullWindow = false; // puts the media element out of full screen in portrait
//media.Width = Window.Current.Bounds.Width; // set bounds of video width to width of screen
}
}
一个简单的
。
解决方法是在 XAML 的媒体元素属性中设置IsFullWindow="True"
,这样无论方向如何,媒体元素都将全屏播放。虽然它总是处于横向模式)。还可以根据需要使用 C# 将媒体元素属性IsFullWindow
设置为 true