c# - Toggling the window visibility instanciates new window -
i have modularized application prism. simple window (shell) displayed. shell contains taskbar icon invokes command toggle windows visibility. clicking taskbaricon creates new instance of shell instead of toggling visibility of original one. know why code not invoke method on first shell?
my bootstrapper
protected override dependencyobject createshell() { var shell = servicelocator.current.getinstance<shell>(); registertypeifmissing(typeof(shell), typeof(shell), true); return shell; } protected override void initializeshell() { var mainwindow = (shell)this.shell; var regionmanager = servicelocator.current.getinstance<iregionmanager>(); application.current.mainwindow = mainwindow; mainwindow.show(); }
my taskbaricon
<tb:taskbaricon name="toolbaricon" iconsource="/resources/images/icon.ico" tooltiptext="some text" leftclickcommand="{staticresource showwindowcommand}"/>
showwindowcommand
public class showwindowcommand : icommand { public void execute(object parameter) { servicelocator.current.getinstance<shell>().togglevisibility(); } public bool canexecute(object parameter) { return true; } public event eventhandler canexecutechanged; }
shell.togglingvisibility()
public void togglevisibility() { if (this.visibility == system.windows.visibility.visible){ this.visibility = system.windows.visibility.collapsed; } else { this.visibility = system.windows.visibility.visible; } }
you're not using singleton shell.
in createshell
first a shell instance, register shell singleton. later on in showwindowcommand.execute
singleton instance, not same non-singleton instance resolved before. how should container know first resolved instance later on used singleton? might have had resolved multiple instances before registering singleton...
Comments
Post a Comment