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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With