Why people use CommandManager.InvalidateRequerySuggested() on ICommands?

后端 未结 4 1064
悲哀的现实
悲哀的现实 2021-02-20 17:23

I am making some custom ICommand implementation of my own and I see A LOT of implementations going like this:

public event EventHandler CanExecuteChanged
{
    a         


        
4条回答
  •  Happy的楠姐
    2021-02-20 17:43

    Very simply - if you are performing heavy work in ICommand.CanExecute() then you are using Commands very badly. If you follow that rule there should in fact be no serious performance implication to calling CommandManager.InvalidateRequerySuggested().

    Pragmatically, it's a much easier implementation than what you've suggested.

    Personally, I rather call CommandManager.InvalidateRequerySuggested() in a particular ViewModel when a property changes so that the feedback to the user is instantaneous (i.e. enabling a button as soon as a form is completed/valid).

提交回复
热议问题