Why my Conductor do not activate his items?

Topics: Getting Started
Aug 26, 2011 at 7:29 PM

Hey, first sorry for my bad english.

I have a VM that is a Conductor<IModule>.Collection.OneActive.
On the constructor I add to the Items property all IModules from my app.

On  this VM view, I show the IModules DisplayName on a listbox and have a ContentControl called "ActiveItem" on wich the selected IModule View appears.

When I select a item on the listbox, I can see the view just fine but the "OnActivate" event of that IModule never gets called because when the code hits the Conductor.ActivateItem method, the "IsActive" poperty is false (I dont know exactly what this means :( )

Sure I could just explicity call ScreenExtensions.TryActivate(ActiveItem) to force the OnActivate but I feel I am doing something wrong here :/

So my question is, should not the item OnActivate be called when the Conductor ActiveItem change?


Aug 28, 2011 at 2:27 PM

Hi 0bscur3, if your Conductor's IsActive property is false, then your Conductor is not getting activated by its parent.  That's where I would start investigating.  In my own code, I would see the same thing happen whenever the parent was a Screen instead of a Conductor.  If that is your case, you may want to change the parent to a Conductor, or use the ActivateWith() extension method.


Aug 28, 2011 at 5:56 PM

Brandon, thanks for your answer... my parent VM already is a Conductor<IModule>.Collection.OneActive and the child views are Screen.

I noticed that if my ShellViewModel is the Conductor, the same code works and the child itens get Activated. If I create another VM and use it inside the ShellViewModel, don't. Maybe I'm using it wrong?

On the ShellView XAML i put:

<ContentControl Name="MainVM" Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"/>

And on the VM:

public MainViewModel MainVM { get; set; }



Aug 30, 2011 at 4:10 AM

Ok, I see.  I think the problem is that the ShellViewModel doesn't know that it needs to activate MainVM... this in turn means MainVM doesn't ever activate any of its children.  So, all you need to do is activate MainVM, and that activation will cascade down the hierarchy.

One way to solve this is to add "MainVM.ActivateWith(this);" after setting MainVM (perhaps in the ShellViewModel constructor, or by making an explicit setter for MainVM and doing it there).

Another way to solve it is to make the ShellViewModel derive from Conductor<MainViewModel>, and then remove the MainVM property (using ActiveItem instead).

Another way is to override OnActivate() on ShellViewModel, and manually call MainVM.Activate().