WPF-Prism CanExecute method not being called

前端 未结 4 1335
南方客
南方客 2021-02-01 19:06

I am coding a simple login UserControl with two TextBoxes (Username and Password) and a Login button. I want the Login button to be enabled only when the username and password f

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 19:55

    Here's a little workaround for Prism (tested with Prism.Core 7.1.0.431):

    public class RelayCommand : DelegateCommand
    {
        public RelayCommand(Action executeMethode) : base(executeMethode)
        {
    
        }
    
        public RelayCommand(Action executeMethode, Func canExecuteMethode) : base(executeMethode, canExecuteMethode)
        {
    
        }
    
        public override event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }
    }
    

提交回复
热议问题