为 WPF 项目使用 TaskbarIcon 库时出现气球通知错误
Balloon Notification Error when using the TaskbarIcon Library for a WPF Project
我正在尝试实现在单击按钮时显示的气球通知,但是我一直收到特定错误:
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
下出现错误。
我已经尝试在通知图标 class 中更改为 public static void
,但这并没有解决任何问题。
您需要在 TaskbarIcon 实例上调用 ShowBalloonTip
TaskbarIcon TBIcon = new TaskbarIcon()
string title = "WPF NotifyIcon";
string text = "This is a standard balloon";
TBIcon.ShowBalloonTip(title, text, BalloonIcon.Error);
我正在尝试实现在单击按钮时显示的气球通知,但是我一直收到特定错误:
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
下出现错误。
我已经尝试在通知图标 class 中更改为 public static void
,但这并没有解决任何问题。
您需要在 TaskbarIcon 实例上调用 ShowBalloonTip
TaskbarIcon TBIcon = new TaskbarIcon()
string title = "WPF NotifyIcon";
string text = "This is a standard balloon";
TBIcon.ShowBalloonTip(title, text, BalloonIcon.Error);