c# - Hide the icon of main window when navigate to another window -
in wpf application, i've 4 windows. every window, i've written following code minimize system tray. problem when navigate 1 window another, first window's icon still appears in system tray. want hide icon when navigate window? please suggest ways proceed?
my main window code is-
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 main window"; globals.ni.visible = true; globals.ni.showballoontip(500); base.onstatechanged(e); } } public void calitemselecteddate(object sender, selectionchangedeventargs e) { datetime d; if (sender 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(); } }
why not have windows share 1 notifyicon? can switch notifyicon's icon when switch views. have global "singleton" holding onto it.
creating new icon each screen means there 4 icons there, , since walk on static reference, no longer have access notifyicon.
Comments
Post a Comment