0

Within my WPF Application I use the "WPF NotifyIcon" (https://www.codeproject.com/Articles/36468/WPF-NotifyIcon-2) library to send OS Ballontips like this

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);

This works fine but now I like to react on clicks on that Ballontip and open specific windows to guide the user. I found that the TaskbarIcon class implements an RoutedEventHandler named TrayBalloonTipClicked which is described as handler for Ballontips clicks.

TrayBalloonTipClicked

Now I could not figure out how to react to such a click event. I am only used to events defined within XAML definitions like Click="Button_Click" where I just implement a method like this

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

Can anybody help? Thank you!

jim__
  • 21
  • 4
  • You are probably looking for something like `tbi.TrayBalloonTipClicked += Tbi_TrayBalloonTipClicked;`. Read about [events and event handlers in C#](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/events/). – dymanoid Aug 09 '18 at 15:39
  • There is a stackoverflow link, as Dymanoid has pointed out, you need the event: https://stackoverflow.com/questions/3181594/handling-a-click-over-a-balloon-tip-displayed-with-trayicons-showballoontip/3181632 – Epistaxis Aug 09 '18 at 15:44
  • I use http://www.hardcodet.net/wpf-notifyicon – jim__ Aug 09 '18 at 15:55

1 Answers1

1

Thanks for your help, you gave me the perfect hints. Now this works fine:

    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();

    } 
jim__
  • 21
  • 4