DisplayRootView - Know when view is visible

Topics: Bootstrappers & IoC, UI Architecture
May 26, 2011 at 12:19 PM

I've overridden DisplayRootView to start my WPF application.  I want to sequence a splash screen, login dialog, then main window.

I can chain these up okay, problem is I can't seem to find an event that fires after my view is visible.  Stepping through the start process:

  1. DisplayRootView is called and does IoC.Get<ViewModel>();
  2. viewmodel constructor is called.
  3. the viewmodel override for OnActivate is called.
  4. DisplayRootView continues and windowManager is initialised
  5. ShowWindow is called to display the view.

Is it correct that OnActivate() on the viewmodel is called before the view is shown?  Is there a way to know in the viewmodel when the attached view is visible?

May 26, 2011 at 12:25 PM

Just discovered OnViewAttached..


Oct 29, 2011 at 10:14 AM

I am new to WPF and CM and i am also looking for a way to find out if a view is visible.

The suggested method OnViewLoaded doesn't seem to work, neither does OnViewAttached.


This for example shows a Messagebox before the view is visible:

protected override void OnViewLoaded(object view)

It looks like the view is only shown after OnViewLoaded is done.

I would like some of my code to be executed just after the view is visible. How would i do that?