据我所知,下面的代码可以从Relay/ICommand Command更改为Delegate命令,并且仍然以相同的方式绑定命令!如果我错了,每个人的差异和用途是什么.
private DelegateCommand something;
public DelegateCommand Something
Run Code Online (Sandbox Code Playgroud)
这是完整的实现
private RelayCommand something;
public ICommand Something
{
get
{
if (something == null)
something = new RelayCommand(SomethingMethod, CanSomething);
return something;
}
}
private bool CanSomething(object parameter)
{
//just for readability return true
return true;
}
private void SomethingMethod(object parameter)
{
using (DatabaseContext context = new DatabaseContext())
{
try { }
catch(Exception ex)
{
throw new ApplicationException(string.Format("Something {0} to {1}", file, directory), ex);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Ree*_*sey 17
框架本身既不存在,DelegateCommand也不RelayCommand存在.它们由第三方图书馆提供.
两者都是ICommand通过接受委托并使用它来提供ICommand实现来实现的.因此,两个类具有相同的意图,并且以基本相同的方式工作.
至于差异 - 可能存在一些微妙的差异,具体取决于您使用的框架.例如,Prism DelegateCommand<T>也有一个概念IActiveAware,用于构建复合命令.
| 归档时间: |
|
| 查看次数: |
9508 次 |
| 最近记录: |