Get reference to the RootVisual

Nov 27, 2010 at 2:05 PM

Hi, I can't see a way of getting a reference to the root visual, or root window that the Bootstrapper code creates.  i.e. if I have:


MyBootStrapper : Bootstrapper<IShellViewModel>

I want to get a reference to the ShellView that the bootstrapper created in DisplayRootView. 

Nov 27, 2010 at 2:05 PM

Should say this is a WPF application

Nov 28, 2010 at 3:15 PM


If your ViewModel inherits  Screen you can use GetView(..) or listen to the OnViewAttached event. But why do you need the view for ? Usually the viewmodel is all you need.


Nov 29, 2010 at 10:09 AM

Thanks, I need to reference to the view because I want the app to be single instanced, and want to activate the current window on launching a second instance of the app.

Nov 29, 2010 at 12:50 PM
Edited Nov 29, 2010 at 12:50 PM

For single instance applications, I created this project that contains an Application-derived object that deals with single isntance identification and inter-process communication (i.e. passing the parameters of a second instance to the first one).

Using that class, you can avoid to get a reference to the root view, since you can manage all the stuff directly inside the boostrapper, hooking to proper events and avoiding to call the DisplayViewRoot if a 'primary' instance is already running. This means that the Shell will not be responsible to honor the single-instance logic (which is, in my opinion, a good idea).

I can provide a simple example if you are interested.

Dec 1, 2010 at 2:22 PM

Thanks BladeWise, that looks like an interesting project!