Files
DevToolsAvalonia/常用工具集/Base/DelegateCommand.cs
2025-08-26 08:37:44 +08:00

51 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace .Base
{
public class DelegateCommand : ICommand
{
public Action<object> ExecuteCommand = null;
public Func<object, bool> CanExecuteCommand = null;
public event EventHandler CanExecuteChanged;
public DelegateCommand()
{
}
public DelegateCommand(Action<object> Command)
{
ExecuteCommand = Command;
}
public bool CanExecute(object paramter)
{
if (CanExecuteCommand != null)
{
return CanExecuteCommand(paramter);
}
else
{
return true;
}
}
public void Execute(object paramter)
{
if (ExecuteCommand != null)
ExecuteCommand(paramter);
}
public void RaiseCanExecuteChanged()
{
if (CanExecuteChanged != null)
CanExecuteChanged(this, EventArgs.Empty);
}
}
}