我有一个C#WPF应用程序,系统托盘中有一个图标。我目前正在使用WPF NotifyIcon,问题是.NET 4.5不允许WPF ContextMenu对象出现在Windows 7任务栏的顶部。
我为托盘图标编写的代码是,
public partial class MonthView : MetroWindow
{
public DateTime SelectedDate { get; set; }
public MonthView()
{
InitializeComponent();
calMain.DisplayDate = DateTime.Today;
Globals._globalController = new AppController();
Globals._globalController.appTaskManager.setupLocal();
Globals._globalController.setMonthViewWindow(this);
Globals.ni = new NotifyIcon();
Globals.ni.Icon = new System.Drawing.Icon(@"D:\MonthView.ico");
Globals.ni.Visible = true;
Globals.ni.Click +=
delegate(object sender, EventArgs args)
{
this.Show();
this.WindowState = WindowState.Normal;
};
}
protected override void OnStateChanged(EventArgs e)
{
if (WindowState == System.Windows.WindowState.Minimized)
{
this.Hide();
Globals.ni.BalloonTipTitle = "MonthView";
Globals.ni.BalloonTipText = "This is main window";
Globals.ni.Visible = true;
Globals.ni.ShowBalloonTip(500);
base.OnStateChanged(e);
}
}
}