how to check if a view is already opened (WindowManager)

Topics: Actions & Coroutines
Sep 8, 2011 at 2:41 PM


I am creating an application where I need the ability to open multiple views (windows) through the menu. The windows should be resizable. So, I am using WindowManager.ShowWindow() method to open views through menu. However, my problem is if the same menu item is click multiple times, it will open multiple instances of the window. I would like to know how to check if view that is being opened is already open and would like to activate it.

the other problem is that I would like to make one window (shellview) as parent and all the windows opening should be the child windows of it. So when shellview is closed, it should check if other windows are still open and it should give a warning before closing the window.


Please help me with this query.




Sep 9, 2011 at 9:10 AM

You could use the Dependency Injection container and make each child window a Singleton.  This would ensure that there is only one instance. 

For the second problem, maybe consider something similar to the CloseStrategy in the HelloScreens example.

Sep 9, 2011 at 12:41 PM

Thanks for the reply.

I made the window as Singleton in the dependency injection Container. Now there are two things:

1. When I click on the menu to open the same window, the window remain minimized and is not shown.

2. When i close the window and try to open it again, following error message id returned:

Cannot set visibility or call Show, ShowDialog, or WindowInteropHelper.EnsureHandle after window is closed.



Sep 9, 2011 at 1:30 PM

If a window is closed it cannot be re-used. This means that every time you need to re-open a window, a new Window object must be created (unless you hide it).

The WindowManager handles this situation properly, re-generating a Window every time a ShowWindow is performed.

This means that in case your window is hidden, and not closed, you need to call the IActivate.Activate() function, instead of WindowManager.ShowWindow(...).

Moreover, note that as long as the IActivate.IsActive flag is true, if the window is managed directly through the WindowManager, the Window is not closed.

Sep 9, 2011 at 2:03 PM


for opening the window, I am using the following code:


var windowManager = Ioc.Get<IWindowManager>();


where ViewModelbase is my ViewModel of type IScreen.


So, first time the window opens properly. Next time nothing happens. I am expecting the window to be shown when I call this next time.

And when i close the window by using window close button or by calling TryClose(), I get the error as mentioned above (Cannot set visibility...).