WPF 本机 Windows 10 祝酒词 [英] WPF native windows 10 toasts

查看:23
本文介绍了WPF 本机 Windows 10 祝酒词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 .NET WPF 和 Windows 10,有没有办法使用 c# 将本地 toast 通知推送到操作中心?我只见过有人为此制作自定义对话框,但必须有一种方法可以通过操作系统来实现.

Using .NET WPF and Windows 10, is there a way to push a local toast notification onto the action center using c#? I've only seen people making custom dialogs for that but there must be a way to do it through the os.

推荐答案

您可以使用 System.Windows.Forms 命名空间中的 NotifyIcon,如下所示:

You can use a NotifyIcon from System.Windows.Forms namespace like this:

class Test 
{
    private readonly NotifyIcon _notifyIcon;

    public Test() 
    {
        _notifyIcon = new NotifyIcon();
        // Extracts your app's icon and uses it as notify icon
        _notifyIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
        // Hides the icon when the notification is closed
        _notifyIcon.BalloonTipClosed += (s, e) => _notifyIcon.Visible = false;
    }

    public void ShowNotification() 
    {
        _notifyIcon.Visible = true;
        // Shows a notification with specified message and title
        _notifyIcon.ShowBalloonTip(3000, "Title", "Message", ToolTipIcon.Info);
    }

}

这应该从 .NET Framework 1.1 开始工作.请参阅 此 MSDN 页面ShowBalloonTip 的参数.

This should work since .NET Framework 1.1. Refer to this MSDN page for parameters of ShowBalloonTip.

我发现,ShowBalloonTip 的第一个参数(在我的示例中为 3000 毫秒)被大量忽略.评论表示赞赏;)

As I found out, the first parameter of ShowBalloonTip (in my example that would be 3000 milliseconds) is generously ignored. Comments are appreciated ;)

这篇关于WPF 本机 Windows 10 祝酒词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆