C# WPF NotifyIcon BalloonTip 和 TrayBalloonTipClicked 事件

C# WPF NotifyIcon BalloonTip and the TrayBalloonTipClicked Event

在我的 WPF 应用程序中,我使用 "WPF NotifyIcon" (https://www.codeproject.com/Articles/36468/WPF-NotifyIcon-2) 库发送 OS 像这样的气球提示

TaskbarIcon tbi = new TaskbarIcon();

string title = "My title";
string text = "My texte...";

//show balloon with custom icon
tbi.ShowBalloonTip(title, text, NotifiyTest_01.Properties.Resources.Error);

这很好用,但现在我喜欢对 Ballontip 上的点击做出反应,并打开特定的 windows 来指导用户。我发现 TaskbarIcon class 实现了一个名为 TrayBalloonTipClicked 的 RoutedEventHandler,它被描述为气球提示点击的处理程序。

现在我不知道如何对这样的点击事件做出反应。我只习惯于 XAML 定义中定义的事件,例如 Click="Button_Click" ,我只是在其中实现了这样的方法

private void Button_Click(object sender, RoutedEventArgs e)
{
}

有人可以帮忙吗?谢谢!

感谢您的帮助,您给了我完美的提示。现在一切正常:

    private void BalloonTip_Clicked(object sender, RoutedEventArgs e)
    {
        //do it...
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {

        string title = "My title";
        string text = "My texte...";

        tbi.TrayBalloonTipClicked += new RoutedEventHandler(BalloonTip_Clicked);

        //show balloon with custom icon
        tbi.ShowBalloonTip(title, text, NotifiyTest_01.Properties.Resources.Error);

        //hide balloon
        tbi.HideBalloonTip();

    }