Windows Phone中的Silverlight 8.1 Toast通知参数 [英] Toast Notification parameters in Windows Phone 8.1 Silverlight

查看:165
本文介绍了Windows Phone中的Silverlight 8.1 Toast通知参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以我用我的8.1 ​​SL的项目,而不是旧ShellToast新ToastNotificationManager。该ShellToast对这使得它很容易敬酒消息NavigationUri。



在新的祝酒词你必须根据的这个文章。然而,它似乎像8.1 SL不具备的情况下的 OnLaunched(LaunchActivatedEventArgs参数)的你应该在App.xaml.cs为监听的参数:




步骤2:处理应用程序的OnLaunched事件



当你敬酒的用户点击,或通过触摸选择它,在
相关联的应用程序被启动,发射了OnLaunched事件。



请注意如果您不包括在祝酒词中
和您的应用程序一经推出属性字符串当选择了面包,则不触发
OnLaunched事件已经在运行。



本示例显示了OnLaunched
的覆盖语法事件中,您将在其中检索并通过Toast通知提供的启动串
采取行动。




 保护覆盖无效OnLaunched(LaunchActivatedEventArgs参数)
{
串launchString = args.Arguments

....
}

我的代码:

  //使用ToastText02敬酒模板。 
ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;

//检索敬酒的内容,因此,我们可以更改文本。
XmlDocument的toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

//查找内容$ B $乙XmlNodeList中toastTextElements = toastXml.GetElementsByTagName文本组件(文字);

//设置敬酒的文本。
//文本在ToastText02模板中的第一行被视为标题文本,并将于大胆。
toastTextElements [0] .AppendChild(toastXml.CreateTextNode(标题));
toastTextElements [1] .AppendChild(toastXml.CreateTextNode(身体));

//设置在吐司
IXmlNode toastNode = toastXml.SelectSingleNode(/土司)的持续时间;
((XmlElement的)toastNode).SetAttribute(时间,长);

//启动PARAMS
字符串中的paramString ={\type\:\toast\,\param1\:\12345\\ \\};
((的XmlElement)toastXml.SelectSingleNode(/土司))的setAttribute(发射中的paramString)。

//使用这个土司规范的实际敬酒的对象。
ToastNotification敬酒=新ToastNotification(toastXml);

//设置SuppressPopup =上,以敬酒忠于直接发送到行动中心没有
//生成用户的手机上的弹出。
toast.SuppressPopup = TRUE;

//发送敬酒。
ToastNotificationManager.CreateToastNotifier()展(面包)。



任何人知道如何解决这个问题?
谢谢


解决方案

您的问题是你设置错了发布参数。您应该直接将它设置为你想要浏览的页面。

  VAR toastNavigationUriString =#/ MainPage.xaml中?参数1 = 12345; 
VAR toastElement =((的XmlElement)toastXml.SelectSingleNode(/土司));
toastElement.SetAttribute(发射,toastNavigationUriString);


Okay so I'm using the new ToastNotificationManager in my 8.1 SL project instead of the old ShellToast. The ShellToast had NavigationUri on the toast message which made it really easy.

In the new toasts you have to specify the launch parameters by yourself according to this article. However it seems like 8.1 SL doesn't have the event OnLaunched(LaunchActivatedEventArgs args) you are supposed to listen for in App.xaml.cs for the parameters:

Step 2: Handle the app's "OnLaunched" event

When the user clicks on your toast or selects it through touch, the associated app is launched, firing its OnLaunched event.

Note If you do not include a launch attribute string in your toast and your app is already running when the toast is selected, the OnLaunched event is not fired.

This example shows the syntax for the override of the OnLaunched event, in which you will retrieve and act on the launch string supplied through the toast notification.

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    string launchString = args.Arguments

    ....
}

My code:

// 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);

Anyone knows how to solve this? Thanks

解决方案

Your problem is you're setting the wrong launch parameter. You should set it directly to the page you want to navigate to.

var toastNavigationUriString = ""#/MainPage.xaml?param1=12345";
var toastElement = ((XmlElement)toastXml.SelectSingleNode("/toast"));
toastElement.SetAttribute("launch", toastNavigationUriString);

这篇关于Windows Phone中的Silverlight 8.1 Toast通知参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆