首页 > 其他 > 详细

MVVM命令绑定原理

时间:2014-10-12 13:17:09      阅读:147      评论:0      收藏:0      [点我收藏+]

跟据网上前辈们的资料。了解到命令在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;

具体这两种变量的含义网上有很多。可以百度。

 

MVVM命令绑定原理

原文:http://www.cnblogs.com/qq247039968/p/4020425.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!