OnActivate, IsActive

Nov 18, 2010 at 3:20 PM


I am attempting a fairly simple implementation with a Conductor and some Screens.

I have the navigation working where my Screen is activated when I click a RadioButton. However, my OnActivate() method is not being executed.

My structure is setup like this:

  • Shell
    • SideMenu
    • Container (Conductor)
      • Search
      • Screen1 (Screen)
      • Screen2 (Screen)

The Container consists of a Grid with two ContentControls. One ContentControl is the Search, and Screen1 or Screen2 is displayed in the ContentControl named "ActiveItem" depending on what is selected from the SideMenu.

So from the SideMenu, I can activate Screen1 by doing this:

public void ShowScreen1()
    containerVM = IoC.Get<ContainerViewModel>();

This works and shows the screen within the Container. I can check containerVM.ActiveItem and see that Screen1 is active. But from within Screen1, my OnActivate() method does not execute.

protected override void OnActivate()
    MessageBox.Show("Screen1 Activated");
Any ideas why this wouldn't work?

Nov 18, 2010 at 3:38 PM

One more thing...

Once Screen1 is active, I check IsActive and it is set to false. Even though the screen is being activated and displayed.

Nov 18, 2010 at 3:39 PM

Is there anything activating your Conductor? One of the "catches" (which I don't know a way around) is that you need to have every Screen or Conductor rooted inside another Conductor for it to work. This ensures that everything gets activated all the way down. If your container Conductor is not activated by a root Conductor, then you will need to activate it manually. You can do this by casting it as IActivate and calling Activate. Does that make sense? Normally the Bootstrapper activates the root VM, if it implements the proper implementation and assuming everything is rooted in that, it works. My guess is that your Shell is not activating your Container.

Nov 18, 2010 at 3:49 PM

That did the trick. My Shell is not a Conductor.

I now call this in my Container constructor:



Am I going about this the best way though? I didn't know of any other way to Activate a Screen inside the Container without making the Container itself a Conductor.


Nov 18, 2010 at 3:52 PM

I don't see an issue with that. My only modification would be to have the shell activate the container explicitly rather than the container activate itself. I think that could create a greater consistency. But it's a very small issue and best that you do whatever is going to make sense to you.

Nov 18, 2010 at 4:01 PM

My Shell now activates the Container. Thanks for your help.