Shell from Conductor<IScreen>.Collection.OneActive Doesn't Activate Children

Topics: Getting Started, UI Architecture
Oct 5, 2012 at 9:20 PM

I'm playing around with CM to see how it works and created a simple collection in a list box in the Shell.  Each item is added by clicking a new button and removed by clicking a remove button on the shell (can remove from the child as well).  I have data converters on the border of the child that respond to the ISActive property on the child.  Everything is working as expected in my sample; however, I have quite a bit of code in the Shell to activate the child item:

                if (this.ActiveItem != null)
                {
                    this.ActiveItem.Activate();
                }

I also have code in the override of the ActivateItem to deactivate the previous child and activate the new child:

        public override void ActivateItem(IScreen item)
        {
            if (item != null && !item.IsActive)
            {
                item.CanClose(result =>
                {
                    canCloseActive = result;
                    NotifyOfPropertyChange(() => CanCloseActive);
                });
                
                if (this.ActiveItem != null)
                {
                    var oldItem = this.ActiveItem;
                    oldItem.Deactivate(false);
                }
                item.Activate();
                
                base.ActivateItem(item);
            }
        }

Is this needed?  It seems to me that all this would have already been wired up.  Am I doing too much to get it to work?

Todd

Coordinator
Oct 6, 2012 at 4:04 AM

That shouldn't be needed. The Conductor does all that.

Oct 8, 2012 at 4:28 PM

Yes.  That is my thought.  Why isn't it working, then?  I have a Viewmodel that is a conductor of type IScreen and viewmodels that are of type IScreen.

    [Export("ModuleBShell")]
    public class ModuleBShellViewModel : Conductor<IScreen>.Collection.OneActive
...
    public class ModuleBCustomerViewModel : Screen
...
    public class ModuleBVendorViewModel : Screen

I load the item viewmodels from the shell viewmodel:

        public void OpenCustomer()
        {
            var screen = new ModuleBCustomerViewModel { DisplayName = "Customer " + customerCount++ };
            screen.PropertyChanged += this.screen_PropertyChanged;
            this.ActivateItem(screen);
        }

Do they need something else to participate in having one item active?

Todd