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

http://stackoverflow.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();
        }
    }

 

posted @ 2016-08-26 15:35  蘑菇mr  阅读(441)  评论(0编辑  收藏  举报