【发布时间】:2014-04-24 17:24:47
【问题描述】:
好的,我在 8.1 SL 项目中使用新的 ToastNotificationManager,而不是旧的 ShellToast。 ShellToast 在 toast 消息中有 NavigationUri,这让它变得非常简单。
在新的 toasts 中,您必须根据this 文章自行指定启动参数。但是,似乎 8.1 SL 没有您应该在 App.xaml.cs 中为参数监听的事件 OnLaunched(LaunchActivatedEventArgs args):
第 2 步:处理应用的“OnLaunched”事件
当用户点击您的 toast 或通过触摸选择它时, 关联的应用程序启动,触发其 OnLaunched 事件。
注意如果你的 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);
有人知道如何解决这个问题吗? 谢谢
【问题讨论】:
-
您可以直接为 toast 提供导航参数。我明天回去工作时会得到详细信息。奇怪的是,我们没有正确记录这一点。
-
感谢期待! :)
-
如果您在 Silverlight 8.1 中使用 ToastNotificationManager,那么您使用什么来代替 OnLoaded 事件,因为 SL 在 App.xaml 中没有该事件?我在 OnNavigatedTo 中有它,但是单击 toast 时它似乎调用了两次我使用下面的加载触发器的答案。??
标签: c# windows-phone-8 windows-phone-8.1 windows-phone-8-sdk