且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-12-21 19:26:34

你应该覆盖 App.Xaml.cs 中的 OnActivated 并像这样处理

You should override OnActivated in App.Xaml.cs and handle this like

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();
                }
            }
        }