我创建了一个桌面应用程序c#,其中我使用了一些引用:
using Microsoft.Toolkit.Uwp.Notifications;
using System.Windows;
using Windows.ApplicationModel.Activation;
using Microsoft.QueryStringDotNET;
我在哪里添加了一些与UWP应用相关的参考:
- Windows.System
- Windows.UI
- Windows.data
- Windows.Foundation
- Windows.ApplicationModel
然后我创建了一个简单的过程来创建和显示我的吐司通知与以下代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
var toastContent = new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = "Surface Launch Party"
},
new AdaptiveText()
{
Text = "Studio S / Ballroom"
},
new AdaptiveText()
{
Text = "4:00 PM, 10/26/2015"
}
}
}
},
Actions = new ToastActionsCustom()
{
Inputs =
{
new ToastSelectionBox("status")
{
DefaultSelectionBoxItemId = "yes",
Items =
{
new ToastSelectionBoxItem("yes", "Going"),
new ToastSelectionBoxItem("maybe", "Maybe"),
new ToastSelectionBoxItem("no", "Decline")
}
}
},
Buttons =
{
new ToastButton("RSVP", "action=rsvpEvent&eventId=63851")
{
ActivationType = ToastActivationType.Foreground
},
new ToastButtonDismiss()
}
},
Launch = "action=viewEvent&eventId=63851"
};
Windows.Data.Xml.Dom.XmlDocument xmldoc = new Windows.Data.Xml.Dom.XmlDocument();
xmldoc.LoadXml(toastContent.GetContent());
var toast = new ToastNotification(xmldoc);
toast.Activated += OnActivated1;
// Create the toast notification
//var toastNotif = new ToastNotification(xmlDoc);
// And send the notification
ToastNotificationManager.CreateToastNotifier("Test").Show(toast);
现在我的问题是我不知道如何检索我在列表中选择的项目:-(
我创建了一个基于toast.Activated事件的过程:
void OnActivated1(ToastNotification sender, object e)
{
var toastActivationArgs = e as ToastNotificationActivatedEventArgs;
}
有了这个事件,我可以检索参数(知道我点击的按钮)但是得到UserInput感谢“ToastNotificationActivatedEventArgs”类似乎是不可能的......你知道它是否可能?是否在桌面应用程序中使用参考UWP的限制?
非常感谢你 !文森特
如果您使用Desktop Bridge构建Win32桌面应用程序,则当前无法在Toast中使用输入和选择框,因为无法检索输入。
如果您正在构建一个普通的Win32应用程序,则必须设置一个COM服务器来处理激活,其中包括用户选择的输入。 This quickstart explains how to set this up for normal Win32 apps。此外,这还将允许您的祝酒词在操作中心中保留,因此如果用户错过了弹出窗口,他们仍然可以从操作中心访问您的祝酒词。
谢谢您的回答。
我的子OnActivated的问题:
void OnActivated1(ToastNotification sender, object e)
{
var toastActivationArgs = e as ToastNotificationActivatedEventArgs;
}
是“e”对象被重新定义为Windows.UI.Notifications.ToastActivatedEventsArgs而不是Windows.ApplicationModel.Activation中的“ToastNotificationActivatedEventArgs”(其中属性Kind,UserInput ..对我来说应该非常有用,以获取内容选定的项目)。
在我的OnActivated1子中,var toastActivationArgs值等于null,因为它无法转换为ToastNotificationActivatedEventArgs。
在我的测试期间,e.arguments等于字符串“action = rsvpEvent&eventId = 63851”,但没有返回XML。这是对象e的唯一可用属性。 (但这对于点击我点击的按钮很有用)
我要检查来自Andrew Bares的链接以尝试设置COM服务器,但我可以看到它是用c ++语言编写的。
谢谢 !
ToastNotificationActivatedEventArgs e.Arguments
应该是一个xml字符串,其中包含您需要准备解析的内容。
首先看看字符串,看看它是否满足你的需要。然后继续使用XMLReader或其他东西来解析它。
你能发帖子吗?