IActivate Conductor

Oct 13, 2010 at 3:35 PM

I have a View Model with multiple conductors.  Currently I have to cast the conductors as IActivate to get them to activate properly. Am I doing something wrong ?

  public class MasterViewModel : ViewModelBase {

        public Conductor<IScreen> Region1 { get; set; }

        public Conductor<IScreen> Region2 { get; set; }
	
        public override void Activate() {
            base.Activate();
            ((IActivate)Region1).Activate();
            ((IActivate)Region2).Activate();
        }

        public override void Deactivate(bool close) {
            base.Deactivate(close);
            ((IDeactivate)Region1).Deactivate(close);
            ((IDeactivate)Region2).Deactivate(close);
        }
}

Oct 13, 2010 at 4:07 PM

No, its ok: IActivate and IDeactivate are implemented explicitly on Screen (the ancestor of Conductor<>) so the corresponding methods are not part of the public interface of the class.
I suppose it was done to descourage erroneous calls to lifecycle interfaces methods, which are usually handled by a conductor.
You scenario is ok, though: MasterViewModel is actually acting as a conductor.

Coordinator
Oct 13, 2010 at 5:53 PM

Marco is correct about the API choice. I know it's a bit nasty in this scenario. If you have this situation occurring a lot...go on over to the full version of Caliburn and grab the source for Conductor<T>.Collection.AllActive  It was designed for your use case. I didn't include it in Micro for size reasons. You also might consider creating some extension methods to handle these scenarios.