开发者

Should I Call RaiseCanExecuteChanged in Prism' DelegateCommand?

开发者 https://www.devze.com 2023-03-11 23:45 出处:网络
I have written a CanExecute method for the DelegateCommand. CanExecute is not being re-evaluated as other commands which inherites from a CommandBase, that looks like this.

I have written a CanExecute method for the DelegateCommand. CanExecute is not being re-evaluated as other commands which inherites from a CommandBase, that looks like this.

public abstract class CommandBase : ICommand
{
    public event EventHandler CanExecuteChanged
    {
        add { CommandManager.RequerySuggested += value; }
        remove { CommandManager.RequerySuggested -= value; }
    }

    public void RaiseCanExecuteChanged()
    {
        CommandManager.InvalidateRequerySuggested();
    }

    public virtual bool CanExecute(object paramete开发者_JAVA技巧r)
    {
        return true;
    }

    public abstract void Execute(object parameter);
}

Can I make the Prism DelegateCommand work like this, so CanExecute is automatically re-evaluated when appropriate or should I manually call RaiseCanExecuteChanged() when needed?


How should the command or the command manager know that it's execution state changed? To have them know about that you need to signal this via the RaiseCanExecuteChanged method.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号