XAML 如何使用WinUI 3添加桌面通知?

doinxwow  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(151)

WinUI 3是否具有添加桌面通知的功能?
参见参考文件(见下文)

sulc1iza

sulc1iza1#

使用内置AppNotification类:

// using Microsoft.Windows.AppNotifications;

public static bool SendNotificationToast(string title, string message)
{
    var xmlPayload = new string($@"
        <toast>    
            <visual>    
                <binding template=""ToastGeneric"">    
                    <text>{title}</text>
                    <text>{message}</text>    
                </binding>
            </visual>  
        </toast>");

    var toast = new AppNotification(xmlPayload);
    AppNotificationManager.Default.Show(toast);
    return toast.Id != 0;
}
34gzjxbg

34gzjxbg2#

  • 安装Nuget软件包:
  • Microsoft.Toolkit.Uwp.Notifications
  • 使用“ToastContentBuilder”生成通知内容。
  • 处理激活
  • 在显示通知后,你可能需要处理用户点击通知的情况。这意味着在用户点击通知后显示特定内容,打开你的应用,或者在用户点击通知时执行操作。

参考编号:
Microsoft Docs

相关问题