首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >来自桌面应用的Windows 10通知: OnActivated事件

来自桌面应用的Windows 10通知: OnActivated事件
EN

Stack Overflow用户
提问于 2017-12-14 01:12:45
回答 3查看 1.4K关注 0票数 1

我创建了一个桌面应用程序c#,其中使用了一些引用:

代码语言:javascript
运行
复制
using Microsoft.Toolkit.Uwp.Notifications;
using System.Windows;
using Windows.ApplicationModel.Activation;
using Microsoft.QueryStringDotNET;

我在其中添加了一些与UWP应用程序相关的引用:

代码语言:javascript
运行
复制
- Windows.System
- Windows.UI
- Windows.data
- Windows.Foundation
- Windows.ApplicationModel

然后,我创建了一个简单的过程来创建并显示我的toast通知,代码如下:

代码语言:javascript
运行
复制
 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事件的过程:

代码语言:javascript
运行
复制
void OnActivated1(ToastNotification sender, object e)
{
    var toastActivationArgs = e as ToastNotificationActivatedEventArgs;


}

有了这个事件,我可以检索参数(以了解我单击的按钮),但由于类"ToastNotificationActivatedEventArgs“,似乎不可能获得UserInput……你知道这是否可能吗?在桌面应用中使用reference UWP有限制吗?

非常感谢!文森

EN

回答 3

Stack Overflow用户

发布于 2017-12-14 02:24:34

如果您正在使用桌面桥构建Win32桌面应用程序,则当前不能在toast中使用输入和选择框,因为无法检索输入。

如果您正在构建一个普通的Win32应用程序,则必须设置一个COM服务器来处理激活,其中将包括用户选择的输入。This quickstart explains how to set this up for normal Win32 apps。此外,这也将允许您的吐司持续存在于操作中心,因此,如果用户错过了弹出窗口,他们仍然可以从操作中心访问您的吐司。

票数 3
EN

Stack Overflow用户

发布于 2017-12-14 16:37:24

感谢您的回答。

我的sub OnActivated的问题是:

代码语言:javascript
运行
复制
void OnActivated1(ToastNotification sender, object e)
{
    var toastActivationArgs = e as ToastNotificationActivatedEventArgs;


}

"e“对象被识别为Windows.UI.Notifications.ToastActivatedEventsArgs,而不是Windows.ApplicationModel.Activation中的"ToastNotificationActivatedEventArgs”(其中属性种类为UserInput..应该是非常有用的,我得到的内容选定的项目)。

在我的OnActivated1子实例中,var toastActivationArgs值等于,因为它不能转换为空

在我的测试中,XML等于字符串"action=rsvpEvent&eventId=63851“,但是没有返回e.arguments。这是对象e的唯一可用属性(但这对于获取我单击的按钮很有用)

我将检查Andrew Bares的链接,尝试设置COM服务器,但我可以看到它是c++语言的。

谢谢!

票数 0
EN

Stack Overflow用户

发布于 2017-12-14 01:37:02

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

首先查看字符串,看看它是否包含您需要的内容。然后使用XMLReader或其他工具来解析它。

你能发布你得到的字符串吗?

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47798757

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档