导航到另一个页面时改变方向 [英] Navigate to another page when orientation changed
问题描述
我将解释什么,我试图在下列情况下做到:
I will explain what I'm trying to do on following instance:
我有两个页面 - MainPage.xaml中(定向人像)和LandscapeLeft.xaml(方向LandscapeLeft)。
I have two pages - MainPage.xaml (orientation Portrait) and LandscapeLeft.xaml (orientation LandscapeLeft).
我想从 MainPage.xaml中
导航到 LandscapeLeft.xaml
当用户旋转手机上Lanscape位置
I want to navigate from MainPage.xaml
to LandscapeLeft.xaml
when user rotate phone on Lanscape position.
我做了如下:
XAML:
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
后面的代码:
protected override void OnOrientationChanged(OrientationChangedEventArgs e)
{
switch (e.Orientation)
{
case PageOrientation.LandscapeLeft:
NavigationService.Navigate(new Uri("/LandscapeLeft.xaml", UriKind.RelativeOrAbsolute));
break;
}
base.OnOrientationChanged(e);
}
当我从PortraitUp旋转手机LandscapeLeft立场发生了什么:结果
首先,MainPage.xaml中的内容旋转景观就在这时,LandscapeLeft.xaml负载。
When I rotate phone from PortraitUp to LandscapeLeft position that what happens:
Firstly, content of MainPage.xaml rotates landscape and just then LandscapeLeft.xaml loads.
我想要做的是消除中的MainPage内容旋转过程的.xaml。它看起来并不好,影响性能。简单地说,当我转我想LandscapeLeft.xaml加载
没有MainPage.xaml中的内容方向的改变以往手机。
What I want to do is to eliminate process of content rotation of MainPage.xaml. It doesn't look good and affects performance. Simply, when I rotate the phone I want LandscapeLeft.xaml to be loaded without previous change of content orientation of MainPage.xaml.
请,有什么建议?
Please, any suggestions?
推荐答案
怎么样把你的内容在一个框架。
当取向事件触发时,改变的不是导航到不同的页面帧内容。
How about putting your contents in a frame. When orientation event fires, change the frame contents instead of navigating to a different page.
...
case PageOrientation.LandscapeLeft:
FrmContents= new LandscapeLeft();
...
这应该解决你的性能问题。
This should sort out your performance issues.
这篇关于导航到另一个页面时改变方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!