且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Prism中命令可用性无法自动刷新

更新时间:2022-09-17 19:51:42

原文:Prism中命令可用性无法自动刷新

http://***.com/questions/2444927/wpf-prism-canexecute-method-not-being-called

It is most likely that the bound control is never asking for the CanExecute state again. You need to call the RaiseCanExecuteChanged method on the DelegateCommand whenever you detect a condition that changes the command's CanExecute state. This signals the bound control to update theCanExecute state.

 

solution

    private void RaiseCanExecuteChanged()
    {
        DelegateCommand<object> command = LoginCommand as DelegateCommand<object>;
        command.RaiseCanExecuteChanged();
    }

    public const string UsernameProperty = "Username";
    private String _username;
    public String Username
    {
        get { return _username; }
        set
        {
            _username = value;
            this.NotifyPropertyChanged(UsernameProperty);
            RaiseCanExecuteChanged();
        }
    }