0

我有一个 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);
        }
    }
} 
4

0 回答 0