简体   繁体   English

在 javascript 中按下 Microsoft Toast 通知按钮时如何运行代码

[英]how to run code when Microsoft toast notification button is pressed in javascript

I am trying to make a microsoft toast notification that has buttons or so called "actions" in this code i have 3 buttons A,B,C and i want to check if any of them are clicked and if so the run a line of code just for example if A is clicked then run debug.log('A') how can i do that?我正在尝试在此代码中制作一个包含按钮或所谓的“操作”的 Microsoft Toast 通知我有 3 个按钮 A、B、C,我想检查是否单击了它们中的任何一个,如果是,则运行一行代码例如,如果单击 A 然后运行 debug.log('A') 我该怎么做? (im new to visual studio and javascript) (我是 Visual Studio 和 javascript 的新手)

document.addEventListener('keydown', logKey);

function logKey(e) {
    var notifLib = Microsoft.Toolkit.Uwp.Notifications;

    var toastContent = new notifLib.ToastContent();
    var toastVisual = new notifLib.ToastVisual();
    var toastBindingGeneric = new notifLib.ToastBindingGeneric();

    var adaptiveText = new notifLib.AdaptiveText();
    adaptiveText.text = "Hello World";
    toastBindingGeneric.children.push(adaptiveText);

    adaptiveText = new notifLib.AdaptiveText();
    adaptiveText.text = "This is a simple toast message";
    toastBindingGeneric.children.push(adaptiveText);

    toastVisual.bindingGeneric = toastBindingGeneric;

    toastContent.visual = toastVisual;

    var toastActionsCustom = new notifLib.ToastActionsCustom();

    var toastButton = new notifLib.ToastButton("a", "action=at&userId=1");
    toastButton.activationType = notifLib.ToastActivationType.background;
    toastActionsCustom.buttons.push(toastButton);

    toastButton = new notifLib.ToastButton("b", "action=b&userId=1");
    toastButton.activationType = notifLib.ToastActivationType.background;
    toastActionsCustom.buttons.push(toastButton);

    toastButton = new notifLib.ToastButton("c", "action=b&userId=1");
    toastButton.activationType = notifLib.ToastActivationType.background;
    toastActionsCustom.buttons.push(toastButton);

    toastContent.actions = toastActionsCustom;

    // Create the toast notification
    var toastNotif = new Windows.UI.Notifications.ToastNotification(toastContent.getXml());

    // And send the notification
    Windows.UI.Notifications.ToastNotificationManager.createToastNotifier().show(toastNotif);
};

for UWP applications, when the notification button is pressed, the activated event of the application will be triggered.对于 UWP 应用程序,当按下通知按钮时,将触发应用程序的activated事件。 In javascript, it can be written like this:在 javascript 中可以这样写:

Windows.UI.WebUI.WebUIApplication.addEventListener("activated", function (activatedEventArgs) {
     if (activatedEventArgs.kind == Windows.ApplicationModel.Activation.ActivationKind.toastNotification) {
          console.log(activatedEventArgs.argument);
     }
});

If you are using WinJs to build your application, you can find the corresponding code block that handles the click of the Toast notification in the app.onactivated event in main.js如果你使用 WinJs 构建你的应用程序,你可以在main.js中的app.onactivated事件中找到对应的处理 Toast 通知点击的代码块

...
else if (args.detail.kind === activation.ActivationKind.launch) {
    if (args.detail.arguments) {
    }
    ...
}
...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取“功能评估需要所有线程运行”并且按钮丢失时如何运行所有线程? - How to run all threads when getting “the function evaluation requires all threads to run” and the button is missing? TFS 2017-如何运行具有代码覆盖率的构建? - TFS 2017 - how to run a build with code coverage? 为什么在将代码添加到已经可用的现有测试时,测试会从 Microsoft Visual Studio 中消失? - Why do tests disappear from Microsoft Visual Studio when adding code to existing tests that already work? 如何通过Microsoft Visual Studio 2017中的JavaScript程序访问Internet? - How can I access the Internet via a JavaScript program in Microsoft Visual Studio 2017? 如何在Visual Studio代码上本地运行/调试Azure云服务? - How to run/debug Azure Cloud Service locally on Visual Studio Code? 使用Typescript时如何查看/调试Javascript - How to view / debug Javascript when using Typescript 在 Visual Studio 中打开解决方案时如何自动运行 dotnet 命令 - How to auto run a dotnet command when opening a solution in visual studio 如何使用SonarQube服务器上的质量配置文件从命令行本地运行代码分析? - How to run a code analysis locally from the command line using a quality profile on the SonarQube server? 如何在VS Code中本地运行.Net Core 2.0应用程序,就像Visual Studio使用SSL一样 - How to locally run .Net Core 2.0 app in VS Code the same way Visual Studio does with SSL 当源代码证明不正确时,调试后的变量如何为NULL - How can debugged variables be NULL when source code proves otherwise
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM