zoukankan      html  css  js  c++  java
  • MVVM命令绑定原理

    跟据网上前辈们的资料。了解到命令在MVVM绑定有三种行式。

    1.DelegateCommand

    2.RelayCommand

    3.AttachbehaviorCommand

     1 /// <summary>
     2     /// Delegatecommand,继承一个命令接口。
     3     /// </summary>
     4     public class DelegateCommand : ICommand
     5     {
     6         Func<object, bool> canExecute;
     7         Action<object> executeAction;
     8         bool canExecuteCache;
     9 
    10         public DelegateCommand(Action<object> executeAction, Func<object, bool> canExecute)
    11         {
    12             this.executeAction = executeAction;
    13             this.canExecute = canExecute;
    14         }
    15 
    16         #region ICommand Members
    17 
    18         public bool CanExecute(object parameter)
    19         {
    20             bool temp = canExecute(parameter);
    21 
    22             if (canExecuteCache != temp)
    23             {
    24                 canExecuteCache = temp;
    25                 if (CanExecuteChanged != null)
    26                 {
    27                     CanExecuteChanged(this, new EventArgs());
    28                 }
    29             }
    30 
    31             return canExecuteCache;
    32         }
    33 
    34         public event EventHandler CanExecuteChanged;
    35 
    36         public void Execute(object parameter)
    37         {
    38             executeAction(parameter);
    39         }
    40 
    41         #endregion
    42     }
    在代码中不难看出这两个变量。
    Func<object, bool> canExecute; Action<object> executeAction;

    具体这两种变量的含义网上有很多。可以百度。http://www.cnblogs.com/fish124423/archive/2012/05/16/2504304.html

    以上只是个人想法和实践经验所得,如果有文字错误和语法错误,请加以指点! QQ:247039968 emil:wujc@younger.com 无论是美女的歌声,还是鬣狗的狂吠,无论是鳄鱼的眼泪,还是恶狼的嚎叫,都不会使我动摇
  • 相关阅读:
    使用过滤器解决JSP页面的乱码问题
    六度空间(MOOC)
    navicat连接mysql出现1251错误
    Saving James Bond
    列出连通集(mooc)
    File Transfer(并查集)
    堆中的路径(MOOC)
    智慧树mooc自动刷课代码
    Hibernate三种状态的区分。
    Hibernate中get和load方法的区别
  • 原文地址:https://www.cnblogs.com/qq247039968/p/4020425.html
Copyright © 2011-2022 走看看