I'm certain that this is a stupidly simple oversight on my part, but I can't get it to work. I have a button with a command property bound to a DelegateCommand that will not enable when I want.
Pretty standard DelegateCommand class
public class DelegateCommand : ICommand
{
public event EventHandler CanExecuteChanged;
Func<object, bool> canExecute;
Action<object> executeAction;
bool canExecuteCache;
public DelegateCommand(Action<object> executeAction, Func<object, bool> canExecute)
{
this.executeAction = executeAction;
this.canExecute = canExecute;
}
public bool CanExecute(object parameter)
{
bool temp = canExecute(parameter);
if (canExecuteCache != temp)
{
canExecuteCache = temp;
if (CanExecuteChanged != null)
{
CanExecuteChanged(this, new EventArgs());
}
}
return canExecuteCache;
}
public void Execute(object parameter)
{
executeAction(parameter);
}
}
Standard declaration in my view model
public DelegateCommand ArchiveData { get; private set; }
In the view model's constructor I have
ArchiveData = new DelegateCommand(m => Cmds.ArchiveSelectedData(this), y => CanArchive());
Finally, I have a CanExecute of
private bool CanArchive()
{
return (DatesPresent || OffSeasonForm) || (PlayerNotes || TravelPlans);
}
The line
return (DatesPresent || OffSeasonForm) || (PlayerNotes || TravelPlans);
refers to 4 bool properties of the view model, bound to the IsChecked properties of 4 different checkboxes. Each bool is a notify property changed property and behaves as expected.
The goal is to have the button disabled until one or more of the checkboxes is checked. However, checking any and all of them fails to change the button's disabled state.
How do I cause the command to check the CanExecute portion?
Thanks