UWP C# - 从通知点击重新启动应用程序
UWP C# - Re-launch app from notification click
我正在编写一个 UWP 应用程序,并且我有一个 ScheduledToastNotification,它会在应用程序暂停时添加到日程表中(例如提醒)。但是,如果我关闭应用程序,通知会准时出现,但是当我点击通知时(没有按钮,通常只是在通知上),应用程序无法正确启动,停在初始屏幕上。
如何让应用程序正确重新启动?
谢谢。
您应该覆盖 App.Xaml.cs
中的 OnActivated
并像
那样处理
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();
}
}
}
我正在编写一个 UWP 应用程序,并且我有一个 ScheduledToastNotification,它会在应用程序暂停时添加到日程表中(例如提醒)。但是,如果我关闭应用程序,通知会准时出现,但是当我点击通知时(没有按钮,通常只是在通知上),应用程序无法正确启动,停在初始屏幕上。
如何让应用程序正确重新启动?
谢谢。
您应该覆盖 App.Xaml.cs
中的 OnActivated
并像
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();
}
}
}