UWP C#-从通知点击重新启动应用

Jas*_*ang 1 c# uwp windows-10-universal

我正在编写一个UWP应用程序,并且我有一个ScheduledToastNotification,当该应用程序挂起时(例如,提醒),该日程表已添加到日程表中。但是,如果我关闭该应用程序,则该通知会按时出现,但是当我单击该通知时(没有按钮,通常是在通知上),该应用程序无法正确启动,并在启动屏幕上停止。

如何正确重新启动应用程序?

谢谢。

Ger*_*xGR 6

您应该覆盖OnActivatedApp.Xaml.cs和处理这个喜欢

protected override void OnActivated(IActivatedEventArgs args)
        {
            if (args.Kind == ActivationKind.ToastNotification)
            {
                var toastArgs = args as ToastNotificationActivatedEventArgs;
                var arguments = toastArgs.Argument;

                if (arguments == "ARG")
                {
                    Frame rootFrame = Window.Current.Content as Frame;
                    if (rootFrame == null)
                    {
                        rootFrame = new Frame();
                        Window.Current.Content = rootFrame;
                    }
                    rootFrame.Navigate(typeof(YOURPAGE));
                    Window.Current.Activate();
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)