namespace Caliburn.Micro.Core { using System; using System.Collections.Generic; /// /// An implementation of that holds on to and activates only one item at a time. /// public partial class Conductor : ConductorBaseWithActiveItem where T: class { /// /// Activates the specified item. /// /// The item to activate. public override void ActivateItem(T item) { if(item != null && item.Equals(ActiveItem)) { if (IsActive) { ScreenExtensions.TryActivate(item); OnActivationProcessed(item, true); } return; } CloseStrategy.Execute(new[] { ActiveItem }, (canClose, items) => { if(canClose) ChangeActiveItem(item, true); else OnActivationProcessed(item, false); }); } /// /// Deactivates the specified item. /// /// The item to close. /// Indicates whether or not to close the item after deactivating it. public override void DeactivateItem(T item, bool close) { if (item == null || !item.Equals(ActiveItem)) { return; } CloseStrategy.Execute(new[] { ActiveItem }, (canClose, items) => { if(canClose) ChangeActiveItem(default(T), close); }); } /// /// Called to check whether or not this instance can close. /// /// The implementor calls this action with the result of the close check. public override void CanClose(Action callback) { CloseStrategy.Execute(new[] { ActiveItem }, (canClose, items) => callback(canClose)); } /// /// Called when activating. /// protected override void OnActivate() { ScreenExtensions.TryActivate(ActiveItem); } /// /// Called when deactivating. /// /// Inidicates whether this instance will be closed. protected override void OnDeactivate(bool close) { ScreenExtensions.TryDeactivate(ActiveItem, close); } /// /// Gets the children. /// /// The collection of children. public override IEnumerable GetChildren() { return new[] { ActiveItem }; } } }