So say I have a button (MyButton) that binds to:
public ICommand MyCommand { get; set; }
I register this command with:
MyCommand = new DelegateCommand<object>(DoSomething);
Now if I do
MyButton.IsEnabled = false;
It doesn’t do anything, i.e., the button is still enabled. I know that the command is causing this to happen because if I remove the new delegatecommand code above then the button appears disabled.
My questions are:
1. Is there a way for me to tell this binding to a command not to mess with my button’s IsEnabled
2. Is there a way to change the visibility via only the commanding property (which would probably be the more correct way anyway)
Thanks!!
You need to add logic into your command for the CanExecute delegate, e.g.:
The “_buttonEnabled” variable should really represent the state of your application that controls whether the button should actually be enabled or disabled. For example, it could be “_isSomethingDone” and be true\false depending on the state of your application. This would then disable your button whilst “DoSomething” is actually doing something.
Rough example: