gpt4 book ai didi

c# - Windows Phone 8.1 Silverlight 中的 Toast 通知参数

转载 作者:可可西里 更新时间:2023-11-01 08:45:01 25 4
gpt4 key购买 nike

好的,所以我在我的 8.1 SL 项目中使用新的 ToastNotificationManager 而不是旧的 ShellToast。 ShellToast 在 toast 消息上有 NavigationUri,这让它变得非常简单。

在新的 toasts 中,你必须根据 this 自行指定启动参数。文章。然而,似乎 8.1 SL 没有事件 OnLaunched(LaunchActivatedEventArgs args) 你应该在 App.xaml.cs 中监听参数:

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

....
}

我的代码:

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com