wpfnon-staticballoon-tip

Balloon Notification Error when using the TaskbarIcon Library for a WPF Project


I'm trying to implement the a Balloon Notification to appear when a button is clicked however I keep receiving a specific error:

An object reference is required for the non-static field, method, or property 
'TaskbarIcon.ShowBalloonTip(string, string, BalloonIcon)

I'm using the library Hardcodet.Wpf.TaskbarNotification;

The Method is

class NotifyIcon
{
    public static void ShowStandardBalloon()
    {
        string title = "WPF NotifyIcon";
        string text = "This is a standard balloon";
        TaskbarIcon.ShowBalloonTip(title, text, BalloonIcon.Error);
    }
}

and is called:

 private void Button_Click(object sender, RoutedEventArgs e)
    {
        NotifyIcon ST = new NotifyIcon();
        ST.ShowStandardBalloon();
    }

Error is appearing under TaskbarIcon.ShowBalloonTip.

I've tried changing to public static void in the Notify Icon class however that didn't resolve anything.


Solution

  • You need to call the ShowBalloonTip on and instance of TaskbarIcon

    TaskbarIcon TBIcon = new TaskbarIcon()
    string title = "WPF NotifyIcon";
    string text = "This is a standard balloon";
    TBIcon.ShowBalloonTip(title, text, BalloonIcon.Error);