Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramDesigner.Additionals/Commands/ControlCommand.cs
2023-01-25 15:58:05 +08:00

105 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
/// <summary>
/// ControlBase可以使用的命令类
/// 使用此类可以使Command具有继承的机制在新的Command中可以调用旧的Command
/// </summary>
public class ControlCommand<T1> : CanExecuteDelegateCommand<ControlCommand<T1>, T1>, IControlCommand
{
public Control Control { get; protected set; }
public IControlCommand Base { get; protected set; }
public string Name { get; set; }
public ControlCommand(Action<ControlCommand<T1>, T1> executeMethod, Func<ControlCommand<T1>, 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<ControlCommand>, IControlCommand
{
public Control Control { get; protected set; }
public IControlCommand Base { get; protected set; }
public string Name { get; set; }
public ControlCommand(Action<ControlCommand> executeMethod, Func<ControlCommand, 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 });
}
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
}