码迷,mamicode.com
首页 > 其他好文 > 详细

MVVM命令绑定原理

时间:2014-10-12 13:35:58      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   sp   div   on   cti   

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

标签:style   blog   color   io   ar   sp   div   on   cti   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!