在WPF项目中使用TaskbarIcon库时出现气球通知错误

时间:2018-09-17 08:09:57

标签: wpf non-static balloon-tip

我试图实现在单击按钮时显示的气球通知,但是我一直收到特定错误:

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

我正在使用图书馆Hardcodet.Wpf.TaskbarNotification;

方法是

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

称为:

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

错误出现在TaskbarIcon.ShowBalloonTip下。

我尝试在“通知图标”类中更改为public static void,但是并没有解决任何问题。

1 个答案:

答案 0 :(得分:0)

您需要调用ShowBalloonTip和TaskbarIcon实例

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