zoukankan      html  css  js  c++  java
  • ICommand.CanExecuteChanged事件订阅对象的变化

     

     public class DelegateCommand : ICommand
        {
            Func<object, bool> canExecute;
            Action<object> executeAction;
            bool canExecuteCache;
            #region 构造函数
            public DelegateCommand()
                : this(null, null)
            {
            }
    
            public DelegateCommand(Action<object> executeAction, Func<object, bool> canExecute)
            {
                this.executeAction = executeAction;
                this.canExecute = canExecute;
    
            }
            #endregion
    
            #region get-set
    
            public Func<object, bool> CanExecuteEx
            {
                get { return canExecute; }
                set { canExecute = value; }
            }
    
            public Action<object> ExecuteActionEx
            {
                get { return executeAction; }
                set { executeAction = value; }
            }
    
            #endregion
    
            #region ICommand Members
    
            public bool CanExecute(object parameter)
            {
                if (canExecute == null) return true;
                bool temp = canExecute(parameter);
    
                if (canExecuteCache != temp)
                {
                    canExecuteCache = temp; 
                }
    
                return canExecuteCache;
            }
    
            //public event EventHandler CanExecuteChanged;
    
            public void Execute(object parameter)
            {
                if (executeAction == null) return;
                executeAction(parameter);
            }
            public event EventHandler CanExecuteChanged
            {
                add { CommandManager.RequerySuggested += value; }
                remove { CommandManager.RequerySuggested -= value; }
            }
            #endregion
        }
    

      

  • 相关阅读:
    spring(1)
    mybatis(7)自定义结果集(一对多/多对一)
    延迟加载
    《构建之法》阅读笔记03
    http socket
    转换
    .net后台通过xmlhttp 和远程服务通讯
    XMLHttpRequest介绍
    js 贪吃蛇
    触发器
  • 原文地址:https://www.cnblogs.com/qq247039968/p/4261345.html
Copyright © 2011-2022 走看看