Why does Conductor.Items contain items from other conductors?

Topics: UI Architecture
Jan 25, 2012 at 4:59 PM

Hi!!

I have a nested view model architecture that looks like this  ([*] is the ActiveItem in the parent conductor):

  • Shell:  Conductor..OneActive
    • Dashboard:  Screen
    • [*] MyNestedView:  Conductor..OneActive
      • Page1:  Screen
      • [*] Page2:  Screen

MyNestedView is the ActiveItem for Shell, and Page2 is the ActiveItem for MyNestedView.  I could have multiple nested conductors.
MyNestedView.Items (or .GetChildren()) returns 3 results:  Dashboard, Page1, Page2.  But I would expect it to only return 2: Page1, Page2.  Why does it return 3 items?  Would it not make more sense to only return the items that are child to this specific conductor?

Ultimately what I am trying to do is Close/Deactivate MyNestedView whenever all of its child items are gone (or just the starting Page1).  I'd like to check against Items.Count and issue a Close Event to deactivate MyNestedView if there are no more children.  If this isn't the best way, can you suggest an alternative?  I haven't had much luck with ActivateWith/ConductWith.

Thank you!

Coordinator
Jan 25, 2012 at 7:13 PM

I'm going to need to look at your code...or a simple repro of the problem. It should not be working as you describe.

Jan 25, 2012 at 8:23 PM

Okay, I made a simple reproduction project.  I can upload it if it's still needed, but I think I've pinpointed the problem.  At first everything worked as described.  I added Windsor and that was also fine, as is using a base class for my conductor.  The items collection went wonky when I changed the type on my base Conductor.

My shell VM is defined follows, it uses Conductor<Screen>:

  public class ShellViewModel : Conductor<Screen>.Collection.OneActive, IShell

My nested VM uses a base conductor, which was fine:

public class NestedViewModel : BaseConductor

But base conductor used a different type (it was fine as Conductor<Screen>):

public abstract class BaseConductor : Conductor<IView>.Collection.OneActive, IView

When I changed the type on the conductor, that's what shows all items when I access the Items property.  I suppose I could leave it as Screen, but I was under the impression Conductor could work with any type of object?