好的,所以我在8.1 SL项目中使用的是新的ToastNotificationManager,而不是旧的ShellToast。 ShellToast在Toast消息上包含了NavigationUri,这非常容易。
在新的 toast 中,您必须根据this文章自行指定启动参数。但是,似乎8.1 SL没有应该在App.xaml.cs中监听以下参数的事件OnLaunched(LaunchActivatedEventArgs args):
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);
关于c# - Windows Phone 8.1 Silverlight中的Toast通知参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23275723/