来自桌面APP的Windows 10通知:OnActivated事件

时间:2017-12-13 17:12:45

标签: c# wpf uwp win-universal-app windows-10-universal

我创建了一个桌面应用程序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

然后我创建了一个简单的程序,用以下代码创建并显示我的Toast通知:

 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是否有限制?

非常感谢! 文森特

3 个答案:

答案 0 :(得分:3)

如果您使用桌面网桥构建Win32桌面应用程序,则目前无法在吐司中使用输入和选择框,因为无法检索输入。

如果您要构建正常的Win32应用程序,则必须设置COM服务器来处理激活,其中包括用户选择的输入。 This quickstart explains how to set this up for normal Win32 apps。此外,这还将允许您的祝酒词在操作中心中保留,因此如果用户错过了弹出窗口,他们仍然可以从操作中心访问您的祝酒词。

答案 1 :(得分:0)

谢谢你的回答。

我的子OnActivated问题:

LIKE

是将“e”对象重新识别为 Windows.UI.Notifications.ToastActivatedEventsArgs 而不是“ ToastNotificationActivatedEventArgs “来自 Windows.ApplicationModel.Activation (其中属性Kind,UserInput ..对我来说非常有用,可以获取所选项目的内容)。

在我的OnActivated1子目录中, var toastActivationArgs 值等于 null ,因为它无法转换为 ToastNotificationActivatedEventArgs

在我的测试期间,e.arguments等于字符串“ action = rsvpEvent& eventId = 63851 ”,但没有返回XML。这是对象e的唯一可用属性。 (但这对于点击我点击的按钮非常有用)

我要查看Andrew Bares的链接,尝试设置一个COM服务器,但我可以看到它是用c ++语言编写的。

谢谢!

答案 2 :(得分:-1)

ToastNotificationActivatedEventArgs e.Arguments应该是一个xml字符串,其中包含您需要准备解析的内容。

首先查看字符串,看看它是否满足您的需求。然后继续使用XMLReader或其他东西来解析它。

你能发帖子吗?

相关问题