如何设置Windows 8.1 C#通知的点击事件



我是Windows开发的新手,在Visual Studio上使用C#和xaml创建了一个Windows 8.1应用程序。我创建了一个祝酒词。

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

但我希望我的用户在点击通知时能用这行代码转移到一个特定的页面。

this.Frame.Navigate(typeof(HomeScreenV2));

我该怎么做?

当您的toast通知被点击时,OnLaunched事件被触发,并且您添加到通知中的任何参数都将在Arguments属性中

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

注意如果您的toast中没有包含启动属性字符串,并且在选择toast时您的应用程序已经在运行,则不会触发OnLaunched事件。

更多信息可以在这里找到

最新更新