using System; using System.Windows.Controls; namespace AIStudio.Wpf.DiagramDesigner.Additionals.Commands { #region ConbrolCommand public interface IControlCommand { void SetControl(Control cb); void SetBase(IControlCommand cc); void Execute(object parameter); } /// /// ControlBase可以使用的命令类 /// 使用此类,可以使Command具有继承的机制,在新的Command中可以调用旧的Command /// public class ControlCommand : CanExecuteDelegateCommand, T1>, IControlCommand { public Control Control { get; protected set; } public IControlCommand Base { get; protected set; } public string Name { get; set; } public ControlCommand(Action, T1> executeMethod, Func, T1, bool> canExecuteMethod = null, bool isAutomaticRequeryDisabled = false, string name = "") : base(executeMethod, canExecuteMethod, isAutomaticRequeryDisabled) { Name = name; } public override bool CanExecute(object parameter) { return base.CanExecute(new object[] { this, parameter }); } public override void Execute(object parameter) { base.Execute(new object[] { this, parameter }); } public virtual void ExecuteBaseCommand(T1 parameter) { if (Base != null) Base.Execute((object)parameter); } public void SetControl(Control cb) { Control = cb; } public void SetBase(IControlCommand cc) { Base = cc; } } public class ControlCommand : CanExecuteDelegateCommand, IControlCommand { public Control Control { get; protected set; } public IControlCommand Base { get; protected set; } public string Name { get; set; } public ControlCommand(Action executeMethod, Func canExecuteMethod = null, bool isAutomaticRequeryDisabled = false, string name = "") : base(executeMethod, canExecuteMethod, isAutomaticRequeryDisabled) { Name = name; } public override bool CanExecute(object parameter) { return base.CanExecute(new object[] { this }); } public override void Execute(object parameter) { base.Execute(new object[] { this }); } public virtual void ExecuteBaseCommand() { if (Base != null) Base.Execute((object)null); } public void SetControl(Control cb) { Control = cb; } public void SetBase(IControlCommand cc) { Base = cc; } } #endregion }