问题
I am new to Windows development and I have created a Windows 8.1 application using C# and xaml on Visual Studio. I have created a toast message.
var template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var element = template.GetElementsByTagName("text")[0];
element.AppendChild(template.CreateTextNode("INR BUDDY"));
var element1 = template.GetElementsByTagName("text")[1];
element1.AppendChild(template.CreateTextNode("You have a message!"));
//set the toast to appear 30 seconds from now
var date = DateTimeOffset.Now.AddSeconds(1);
var stn = new ScheduledToastNotification(template, date);
notifier.AddToSchedule(stn);
IXmlNode toastNode = template.SelectSingleNode("/toast");
But I want my user to be transferred to a specific page with this line of code when they click the notification.
this.Frame.Navigate(typeof(HomeScreenV2));
How do I do this?
回答1:
When your toast notification is clicked the OnLaunched event is fired and any parameters you have added to your notification will be in the Arguments
property
App.cs
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
//parameters from Toast
if (!string.IsNullOrEmpty(e.Arguments))
{
string arguments= e.Arguments;
if (arguments == "Whatever")
{
this.Frame.Navigate(typeof(HomeScreenV2));
}
}
}
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.
More can be found here
来源:https://stackoverflow.com/questions/29201315/how-to-set-click-event-for-notification-windows-8-1-c-sharp