mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-27 11:43:24 +08:00
35 lines
993 B
C#
35 lines
993 B
C#
|
|
using System;
|
|||
|
|
using System.Windows.Input;
|
|||
|
|
|
|||
|
|
namespace Showcase.WPF.DragDrop.ViewModels
|
|||
|
|
{
|
|||
|
|
public class SimpleCommand : ICommand
|
|||
|
|
{
|
|||
|
|
public SimpleCommand(Action<object> execute = null, Predicate<object> canExecute = null)
|
|||
|
|
{
|
|||
|
|
this.CanExecuteDelegate = canExecute;
|
|||
|
|
this.ExecuteDelegate = execute;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public Predicate<object> CanExecuteDelegate { get; set; }
|
|||
|
|
|
|||
|
|
public Action<object> ExecuteDelegate { get; set; }
|
|||
|
|
|
|||
|
|
public bool CanExecute(object parameter)
|
|||
|
|
{
|
|||
|
|
var canExecute = this.CanExecuteDelegate;
|
|||
|
|
return canExecute == null || canExecute(parameter);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public event EventHandler CanExecuteChanged
|
|||
|
|
{
|
|||
|
|
add { CommandManager.RequerySuggested += value; }
|
|||
|
|
remove { CommandManager.RequerySuggested -= value; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void Execute(object parameter)
|
|||
|
|
{
|
|||
|
|
this.ExecuteDelegate?.Invoke(parameter);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|