[英]Navigating from App.xaml.cs when receiving push notification
Hi i want my app to navigate to a page when i receive a push toast notification. 嗨,我希望我的应用程序在收到推送敬酒通知时导航到页面。 My code is as follows:-
我的代码如下:
ParsePush.ToastNotificationReceived += OnPushNotification;
This is to handle the event of push 这是为了处理推送事件
private async void OnPushNotification(object sender, Windows.Networking.PushNotifications.PushNotificationReceivedEventArgs e)
{
var AdFrame = Window.Current.Content as Frame;
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
if (localSettings.Values.ContainsKey("Suspended"))
{
String value = localSettings.Values["Suspended"].ToString();
if (value != null)
{
if (value == "false")
{
AdFrame.Navigate(typeof(Ad));
}
}
}
}
I get a Null Reference Error at var AdFrame = Window.Current.Content as Frame;
我在
var AdFrame = Window.Current.Content as Frame;
收到Null引用错误var AdFrame = Window.Current.Content as Frame;
I have added this code in App.xaml.cs .I just want to navigate to the Ad Page from current page , whatever page maybe active. 我已经在App.xaml.cs中添加了此代码。我只想从当前页面导航到“广告页面”,无论页面处于活动状态。 I am pretty new to windows , any help will be appreciated.
我是Windows的新手,将不胜感激。
You will need to display a toast notification instead: 您将需要显示敬酒通知:
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(
ToastTemplateType.ToastImageAndText02);
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
stringElements.Item(0).AppendChild(toastXml.CreateTextNode("Hello world!"));
IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
XmlAttribute launchAttribute = toastXml.CreateAttribute("launch");
launchAttribute.Value = "pass data here"; // TODO: pass data here
toastNode.Attributes.SetNamedItem(launchAttribute);
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
When user clicks on the toast notification, you can handle the App launch event and then read the data. 当用户单击烤面包通知时,您可以处理应用启动事件,然后读取数据。
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
// ...
MainPage page = rootFrame.Content as MainPage;
page.ParseData(e.Arguments);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.