[英]Toast Notification parameters in Windows Phone 8.1 Silverlight
好的,所以我在8.1 SL项目中使用新的ToastNotificationManager而不是旧的ShellToast。 ShellToast在toast消息上有NavigationUri,这非常容易。
在新的祝酒词你必须根据自己指定的启动参数此文章。 但是看起来8.1 SL没有事件OnLaunched(LaunchActivatedEventArgs args)你应该在App.xaml.cs中监听参数:
第2步:处理应用程序的“OnLaunched”事件
当用户点击您的祝酒词或通过触摸选择它时,相关的应用程序将启动,同时启动其OnLaunched事件。
注意如果您在Toast中未包含启动属性字符串,并且在选择Toast时您的应用程序已在运行,则不会触发OnLaunched事件。
此示例显示了OnLaunched事件的覆盖语法,您将在其中检索并处理通过Toast通知提供的启动字符串。
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
string launchString = args.Arguments
....
}
我的代码:
// Using the ToastText02 toast template.
ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
// Retrieve the content part of the toast so we can change the text.
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
//Find the text component of the content
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
// Set the text on the toast.
// The first line of text in the ToastText02 template is treated as header text, and will be bold.
toastTextElements[0].AppendChild(toastXml.CreateTextNode("Heading"));
toastTextElements[1].AppendChild(toastXml.CreateTextNode("Body"));
// Set the duration on the toast
IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("duration", "long");
//Launch params
string paramString = "{\"type\":\"toast\",\"param1\":\"12345\"}";
((XmlElement)toastXml.SelectSingleNode("/toast")).SetAttribute("launch", paramString);
// Create the actual toast object using this toast specification.
ToastNotification toast = new ToastNotification(toastXml);
// Set SuppressPopup = true on the toast in order to send it directly to action center without
// producing a popup on the user's phone.
toast.SuppressPopup = true;
// Send the toast.
ToastNotificationManager.CreateToastNotifier().Show(toast);
谁知道如何解决这个问题? 谢谢
您的问题是您正在设置错误的launch
参数。 您应该将其直接设置为要导航到的页面。
var toastNavigationUriString = ""#/MainPage.xaml?param1=12345";
var toastElement = ((XmlElement)toastXml.SelectSingleNode("/toast"));
toastElement.SetAttribute("launch", toastNavigationUriString);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.