You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WinUI 3程序如何实现Windows 11持久化桌面通知?

实现WinUI 3通知持续显示直到用户操作

可以通过代码实现该需求,无需修改系统全局设置。WinUI 3的AppNotification底层依赖Windows Toast通知框架,我们可以通过配置通知的**场景(Scenario)**来让通知保持显示,直到用户点击或关闭它。

方法:使用AppNotificationToastScenario.Reminder场景

通过AppNotificationBuilder的AddToastScenario方法,将通知场景设置为Reminder,这类通知会持续显示在屏幕上,直到用户主动操作,而非自动隐藏到通知中心。

修改你的代码如下:

internal static bool SendPersistentNotification(string title, string message)
{
    try
    {
        AppNotification toast = new AppNotificationBuilder()
            .AddText(title)
            .AddText(message)
            // 设置为提醒场景,通知将持续显示至用户操作
            .AddToastScenario(AppNotificationToastScenario.Reminder)
            .BuildNotification();

        AppNotificationManager.Default.Show(toast);
        return toast.Id != 0;
    }
    catch (Exception ex)
    {
        return false;
    }
}

可选场景说明

除了Reminder,还有两种场景可实现类似的持久显示效果:

  • AppNotificationToastScenario.Alarm:适用于闹钟类通知,会伴随重复提醒音,强制用户关注
  • AppNotificationToastScenario.IncomingCall:模拟来电通知,同样会持续显示并带有专属提醒样式

原理说明

这些场景是Windows Toast通知框架提供的内置行为,通过代码指定场景后,系统会自动调整通知的显示逻辑,覆盖默认的自动隐藏规则,无需修改系统全局设置。

内容的提问来源于stack exchange,提问作者Borisonekenobi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 01:37:07