我想知道如何在启动时直接检查当前方向(MainPage LoadedEvent)。
以下代码不起作用:
public MainPage()
{
InitializeComponent();
Loaded += MainPage_Loaded;
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine(Orientation);
if (Orientation == PageOrientation.Landscape || Orientation == PageOrientation.LandscapeLeft)
Debug.WriteLine("Simulator and Device won't jump in here on startup (always PortraitUp)...");
}
为什么它会这样?我在哪里可以正确定位?
(我已启用SupportedOrientations="PortraitOrLandscape"
,应用程序将从头开始直接显示在横向视图中。)
Ps。:当然,设备和模拟器在启动时处于风景中;)
答案 0 :(得分:1)
您是否添加了Orientation属性?
<phone:PhoneApplicationPage
x:Class="Orientation.MainPage"
SupportedOrientations="PortraitOrLandscape" Orientation="Landscape"
>
答案 1 :(得分:-1)
希望这就是你要搜索的内容
private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
if ((e.Orientation & PageOrientation.Portrait) == (PageOrientation.Portrait))
{
// if portrait
}
else
{
// If landscape
}
}
在您的以下xaml代码中:
<phone:PhoneApplicationPage
x:Class="Orientation.MainPage"
SupportedOrientations="PortraitOrLandscape" Orientation="Landscape"
>
包括OrientationChanged =“PhoneApplicationPage_OrientationChanged”
<phone:PhoneApplicationPage
x:Class="Orientation.MainPage"
SupportedOrientations="PortraitOrLandscape"
OrientationChanged="PhoneApplicationPage_OrientationChanged"
>