我试图实现在单击按钮时显示的气球通知,但是我一直收到特定错误:
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
,但是并没有解决任何问题。
答案 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);