| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System;
- using System.Windows.Input;
- namespace SHJX.Service.Common.ElementHelper
- {
- /// <summary>
- /// 实现DelegateCommand
- /// </summary>
- class CustomDelegateCommand : ICommand
- {
- #region Property
- /// <summary>
- /// 命令所需执行的事件
- /// </summary>
- public Action<object> ExecuteCommand { get; set; }
- /// <summary>
- /// 命令是否可用所执行的事件
- /// </summary>
- public Func<object, bool> CanExecuteCommand { get; set; }
- #endregion
- public CustomDelegateCommand() { }
- public CustomDelegateCommand(Action<object> execute, Func<object, bool> canexecute)
- {
- ExecuteCommand = execute;
- CanExecuteCommand = canexecute;
- }
- /// <summary>
- /// 命令可用性获取
- /// </summary>
- /// <param name="parameter"></param>
- /// <returns></returns>
- public bool CanExecute(object parameter)
- {
- return CanExecuteCommand(parameter);
- }
- public event EventHandler CanExecuteChanged
- {
- add { CommandManager.RequerySuggested += value; }
- remove { CommandManager.RequerySuggested -= value; }
- }
- /// <summary>
- /// 命令具体执行
- /// </summary>
- /// <param name="parameter"></param>
- public void Execute(object parameter)
- {
- ExecuteCommand(parameter);
- }
- }
- }
|