Prism Delegate command does not enable power button

I am trying to enable and disable a button in a WPF user control (PRISM) based on user input.

In the constructor I do SubmitCommand = new DelegateCommand<object>(OnSubmit, CanSubmit); public ICommand SubmitCommand { get; private set; } private void OnSubmit(object arg) { _logger.Log(arg.ToString()); } private bool CanSubmit(object arg) { return Title.Length > 0; } private string _title=""; public string Title { get { return _title; } set { if (_title != value) { _title = value; this.RaisePropertyChanged(); } } } 

I linked the SubmitCommand command in Xaml as shown below

 <Button Content="Submit" Width="100" Command="{Binding Path=SubmitCommand}" CommandParameter="{Binding ElementName=TitleText, Path=Text}" /> 

The problem is changing the name value, the button does not turn on. Maybe I'm missing something. Thank you for your help!

+4
source share
2 answers

It looks like you need to raise the CanExecuteChanged event on your team. For more information see http://wpftutorial.net/DelegateCommand.html and http://msdn.microsoft.com/en-us/library/system.windows.input.icommand.canexecutechanged.aspx

Please note that the first link is related to the implementation of DelegateCommand and is probably not what you are actually using. For the DelegateCommand prism, you just need to call the RaiseCanExecuteChanged() method if you want to determine if the button should be reinstalled.

Good luck

Nat

+5
source

Add

  SubmitCommand.RaiseCanExecuteChanged(); 

After:

  this.RaisePropertyChanged(); 
0
source

All Articles