在我的Wpf應用程序中,我有四個窗口。對於每個窗口,我都寫了下面的代碼,這樣可以最小化系統托盤。但問題是從一個窗口導航到另一個窗口時,第一個窗口的圖標仍然出現在系統托盤中。導航到另一個窗口時,我只想隱藏該圖標?請提出進行的方法?導航到另一個窗口時隱藏主窗口的圖標
我的主窗口的代碼是 -
public partial class MonthView : MetroWindow
{
public DateTime SelectedDate { get; set; }
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
public MonthView()
{
InitializeComponent();
calMain.DisplayDate = DateTime.Today;
Globals._globalController = new AppController();
Globals._globalController.appTaskManager.setupLocal();
Globals._globalController.setMonthViewWindow(this);
Globals.ni = new NotifyIcon();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
Globals.ni.Icon = TimeSheet.Properties.Resources.MonthViewIcon;
Globals.ni.Visible = true;
Globals.ni.Click +=
delegate(object sender, EventArgs args)
{
this.Show();
this.WindowState = WindowState.Normal;
};
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1 });
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem2 });
this.menuItem1.Text = "Start";
this.menuItem2.Text = "Exit";
Globals.ni.ContextMenu = this.contextMenu1;
}
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);
}
}
public void calItemSelectedDate(object sender, SelectionChangedEventArgs e)
{
DateTime d;
if (sender is DateTime)
{
d = (DateTime)sender;
}
else
{
DateTime.TryParse(sender.ToString(), out d);
}
SelectedDate = d;
ShowActivity(d);
}
public void ShowActivity(DateTime date)
{
DayView Activity = new DayView(date);
Activity.Show();
this.Hide();
}
private void SetButton_Click(object sender, RoutedEventArgs e)
{
SettingsView set = new SettingsView();
set.Show();
this.Hide();
}
}
如果這是一個WPF項目,爲什麼使用'System.Windows.Forms.ContextMenu's和'System.Windows.Forms.MenuItem's?否則,如果這不是WPF項目,爲什麼要添加WPF標記? – Sheridan