Xamarin.forms Xamarin表单恢复特殊处理

Xamarin.forms Xamarin表单恢复特殊处理,xamarin.forms,navigation,cross-platform,onresume,Xamarin.forms,Navigation,Cross Platform,Onresume,当我的Xamarin Forms跨平台应用程序恢复时,我想截取导航并转移到我拥有的加载页面,该页面检查某些数据是否已更改等。执行此处理后,如果没有任何更改,我想恢复到onresume将带我去的原始页面的导航 因此,首先,我在app.xaml.cs文件中的一个变量中保存了一个页面实例,用于检查数据中的更改。当我的应用程序启动时,我创建了一个我想要的页面实例并导航到它。下面是我的app.xaml.cs文件中的代码: gobj_BaseLoadingPage = new bas

当我的Xamarin Forms跨平台应用程序恢复时,我想截取导航并转移到我拥有的加载页面,该页面检查某些数据是否已更改等。执行此处理后,如果没有任何更改,我想恢复到onresume将带我去的原始页面的导航

因此,首先,我在app.xaml.cs文件中的一个变量中保存了一个页面实例,用于检查数据中的更改。当我的应用程序启动时,我创建了一个我想要的页面实例并导航到它。下面是我的app.xaml.cs文件中的代码:

            gobj_BaseLoadingPage = new baseloadingpage();

            if (Application.Current.MainPage == null)
            {
                Application.Current.MainPage = new NavigationPage(gobj_BaseLoadingPage);
            }
现在在简历中,我想回到这个加载页面。我尝试了下面代码的许多变体,但似乎无法使其正常工作。使用下面的代码,按基本加载页面永远不会显示,应用程序只会返回到暂停时所在的页面

        App.Current.MainPage = (Page)gobj_BaseLoadingPage.Parent;
        gobj_BaseLoadingPage.Parent = null;
        Application.Current.MainPage.Navigation.PushAsync(gobj_BaseLoadingPage);
如果我只是对页面执行pushasync,而没有清除其父级,则会得到一个错误,即页面不能已经有父级

如果您有任何建议,我们将不胜感激。

请使用、
InsertPageBefore
PopAsync
。(未显示任何保存状态):

Page rootPage;

public App()
{
  InitializeComponent();

  rootPage = new OriginalRootPage();
  MainPage = new NavigationPage(rootPage);
}

protected override async void OnResume()
{
  // Handle when your app resumes
  Debug.WriteLine("Resume");

  var nav = MainPage.Navigation;

  // Pops all but the root Page off the navigation stack, 
  // making the root page of the application the active page.
  await nav.PopToRootAsync();

  if (!(nav.NavigationStack.First() is NewRootPage))
  {
    // Insert a page on the navigation stack before the original rootPage
    var newRootPage = new NewRootPage();
    nav.InsertPageBefore(newRootPage, rootPage);

    // Pops the original rootPage, making the newRootPage the only page on the stack
    await nav.PopAsync();
  }
}