【发布时间】:2015-06-22 18:04:22
【问题描述】:
在 Windows Phone 8.1 上,我正在执行 OrientationChanged 事件,在该事件中,当处于横向模式时,媒体元素将变为全窗口,效果很好。但是当我旋转到纵向时,它不会在纵向模式下从整个窗口退回到其屏幕宽度。事实上,它什么也没做。问题是事件处理程序检测到横向而不是纵向?我错过了什么? MediaElement 似乎卡在IsFullWindow = true 中,并且不再检查orientationchanged 事件方法。
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>
C#
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
}
}
【问题讨论】:
-
您使用的是 Windows Phone 8.1 还是 Silverlight 8.1?
标签: c# xaml event-handling windows-phone windows-phone-8.1