【问题标题】:xamarin.forms notification tap and navigation from app.xaml.cs来自 app.xaml.cs 的 xamarin.forms 通知点击和导航
【发布时间】:2019-09-24 10:54:07
【问题描述】:

我有一个 xamarin.forms 应用程序,我在其中使用 Plugin.LocalNotification Link 在 android 和 ios.Notifications 中进行本地推送通知工作正常。问题是我想在点击 android 和 ios 中的通知时打开我的共享屏幕之一。我根据文档谎言完成了点击。

在我的 App.xamal.cs 中

    public App()
            {
                InitializeComponent();

 Application.Current.MainPage = new NavigationPage(new LandingPage());
                NotificationCenter.Current.NotificationTapped += OnLocalNotificationTapped;                  
            }

            private void OnLocalNotificationTapped(NotificationTappedEventArgs e)

            {          

                        MainPage = new NavigationPage(new SECLandingScreen(Isnotification));
                        ((NavigationPage)MainPage).BarBackgroundColor = Color.FromHex("#19110F");
                        ((NavigationPage)MainPage).BarTextColor = Color.Snow;               
                }
            }

我的问题

点击通知时,我可以导航到通知屏幕。但是我无法通过按返回按钮导航到上一个屏幕。从任何屏幕单击通知并在返回时导航到上一个屏幕的导航应该如何?

【问题讨论】:

  • 您需要获取对当前导航堆栈的引用并将新页面推送到其上,而不是为 MainPage 分配新值(这会删除任何以前的导航)
  • @Jason 你能给我一些sn-p吗?
  • 检查 MainPage 是否已经是 NavigationPage 的实例,如果是,则使用它来 PushAsync 一个新页面
  • @Jason 在启动时进行正常导航,我使用 Application.Current.MainPage = new NavigationPage(new LandingPage());

标签: xamarin.forms


【解决方案1】:

如果 MainPage 已经是 NavigationPage 的实例,则使用它来 PushAsync 一个新页面

var nav = (NavigationPage)MainPage;

if (nav != null) 
{
  nav.PushAsync(new SECLandingScreen(Isnotification));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多