如何为通知设置单击事件 Windows 8.1 C# [英] How to set click event for notification Windows 8.1 C#
问题描述
我是 Windows 开发的新手,我在 Visual Studio 上使用 C# 和 xaml 创建了一个 Windows 8.1 应用程序.我创建了一个 Toast 消息.
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));
我该怎么做?
推荐答案
当你的 toast 通知被点击时,OnLaunched 事件被触发,你添加到通知中的任何参数都将在 Arguments
属性中
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));
}
}
}
注意如果您没有在 toast 中包含启动属性字符串,并且在选择 toast 时您的应用已经在运行,则不会触发 OnLaunched 事件.
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.
更多信息可在此处
这篇关于如何为通知设置单击事件 Windows 8.1 C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!