wpf中mvvm的Command綁定后,如何在點擊按鈕的時候在viewmodel里面異步執行方法。
1 回答

慕妹3146593
TA貢獻1820條經驗 獲得超9個贊
主要是你手動觸發事件就行了!~ 改變 CanExecute的返回值,再手動觸發 CanExecuteChanged 事件就OK啦!
public class AAACommand : ICommand
{
private bool _isRun;
public bool CanExecute(object parameter)
{
return !_isRun;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
_isRun = true;
if (CanExecuteChanged == null)
{
CanExecuteChanged(this, new EventArgs());
}
// 你的代碼
_isRun = false;
if (CanExecuteChanged == null)
{
CanExecuteChanged(this, new EventArgs());
}
}
}
- 1 回答
- 0 關注
- 1030 瀏覽
添加回答
舉報
0/150
提交
取消