【发布时间】:2017-12-05 12:51:55
【问题描述】:
我正在使用 Xamarin Forms (2.3.4.247),而我的应用程序正在使用“HamburgerMenu”。要在页面之间切换,我正在使用它的代码:
private FirstPage firstPage; //it's i get from the constructor
private SecondPage secondPage = new SecondPage();
private ThirdPage thirdPage = new ThirdPage();
private async void ItemSelectedMethod()
{
var root = App.NavigationPage.Navigation.NavigationStack[0];
if (SelectedItem == Items[0])
{
if (!IsFirstChoose)
{
App.NavigationPage.Navigation.InsertPageBefore(firstPage, root);
await App.NavigationPage.PopToRootAsync(false);
}
}
if (SelectedItem == Items[1])
{
App.NavigationPage.Navigation.InsertPageBefore(secondPage, root);
await App.NavigationPage.PopToRootAsync(false);
}
if (SelectedItem == Items[2])
{
App.NavigationPage.Navigation.InsertPageBefore(thirdPage, root);
await App.NavigationPage.PopToRootAsync(false);
}
IsFirstChoose = false;
rootPageViewModel.IsPresented = false;
}
在 Android 和 Windows 10 桌面上一切正常,在 Windows 10 Mobile 模拟器上,当我在 thirdPage 和 firstPage 之间切换时,我的应用程序崩溃了。 FirstPage 是根目录:
FirstPage firstPage = new FirstPage();
NavigationPage = new NavigationPage(firstPage);
我不知道为什么...模拟器不允许调试...
第二件事: 当我将 Xamarin Forms 更新到版本 2.3.5.256-pre6 时,我的应用程序抛出异常“System.ArgumentException:'无法插入已经在导航堆栈中的页面'”......但是当我将代码更改为:
App.NavigationPage.Navigation.InsertPageBefore(new ThirdPage(), root);
App.NavigationPage.Navigation.InsertPageBefore(new SecondPage(), root);
//etc
一切正常... 有谁知道为什么会这样?我不想在页面切换时创建新对象...
【问题讨论】:
标签: c# xamarin xamarin.forms xamarin.uwp