恭喜,你发布的帖子
发布于 2020-02-01 21:51:15
2楼
2.2:ICommand的实现如下。这个测试中也另外用到了Prism的第三方实现的ICommand类库,通过nuget添加。
ICommand中方法的执行需要经过判定,并且判定结果的变化会通过事件通知。我觉得这种比较麻烦就没有采用,而是在ViewModel中采用做为属性的Flag来实现通知和禁用UI元素的机制
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace WpfApp01.ViewModels
{
public class ClassICommand : ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
if (this.ExcuteAction == null)
{
return;
}
this.ExcuteAction(parameter);
}
public Action<object> ExcuteAction;
}
}
请填写推广理由:
分享
只看
楼主