0

我正在尝试实现单击按钮时出现的气球通知,但是我不断收到特定错误:

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在通知图标类中更改为,但这并没有解决任何问题。

4

1 回答 1

0

您需要在 TaskbarIcon 和实例上调用 ShowBalloonTip

TaskbarIcon TBIcon = new TaskbarIcon()
string title = "WPF NotifyIcon";
string text = "This is a standard balloon";
TBIcon.ShowBalloonTip(title, text, BalloonIcon.Error);
于 2018-09-17T11:38:43.540 回答