We're trying to use an ICommand to set up a button in Silverlight with Prism. We'd like the button to be disabled on occasion. DelegateCommand takes 2 parameters, an "ExecuteMethod" and a "CanExecuteMethod"
When we set up the ICommand we expect that if the "CanExecuteMethod" is used, then it will be called to see if the "ExecuteMethod" can be called. The button's Enabled state should reflect the result of the "CanExecuteMethod"
What we actually see: When the form is created, the method is called and the button is enabled or disabled. (in this case, Enabled) The CanExecuteMethod is never called again and the Execute method will fire even though we've tried to set behavior to keep that from happening. Execption is thrown (what we'd like to avoid).
The obvious answer is that we should be calling some sort of :
OnPropertyChanged("SaveCommand");
but we're doing it wrong somehow. Either we're assuming that it works a way that it doesn't, or we're missing a step. Any Ideas?
Code:
SaveCommand = new DelegateCommand<string>(OnSaveCommand, CanSave);
public void OnSaveCommand( string helpNumber )
{
OnPropertyChanged("SaveCommand");
//DoSaveStuff
}
public bool CanSave(Object sender)
{
return Model.CanSave();// true or false depending
}