簡體   English   中英

Windows Phone 8.1 Silverlight中的Toast Notification參數

[英]Toast Notification parameters in Windows Phone 8.1 Silverlight

好的,所以我在8.1 SL項目中使用新的ToastNotificationManager而不是舊的ShellToast。 ShellToast在toast消息上有NavigationUri,這非常容易。

在新的祝酒詞你必須根據自己指定的啟動參數文章。 但是看起來8.1 SL沒有事件OnLaunched(LaunchActivatedEventArgs args)你應該在App.xaml.cs中監聽參數:

第2步:處理應用程序的“OnLaunched”事件

當用戶點擊您的祝酒詞或通過觸摸選擇它時,相關的應用程序將啟動,同時啟動其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);

誰知道如何解決這個問題? 謝謝

您的問題是您正在設置錯誤的launch參數。 您應該將其直接設置為要導航到的頁面。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM