好的,所以我在我的8.1 SL项目中使用了新的ToastNotificationManager而不是旧的ShellToast。ShellToast有一个NavigationUri属性,使得它非常易用。
在新的toast中,根据这篇文章,你必须自己指定启动参数。然而,在App.xaml.cs中监听OnLaunched(LaunchActivatedEventArgs args)事件以获取参数在8.1 SL中似乎并不存在:
第二步:处理应用程序的"OnLaunched"事件
当用户单击您的toast或通过触摸选择时,相关联的应用程序将启动,触发其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);
有人知道如何解决这个问题吗? 谢谢