I have a WPF application window with a set of three buttons (Button A, B, C) and these buttons have command binding to respective View Model property.
When Button A is clicked it’s command executes (another application is launched, Button A is disabled as CommandCanExecute condition is updated to return false). This results in application window being deactivated.
Clicking Button B doesn’t execute it’s command but instead only activates the window and sets the focus to the Main window. 2nd click is required on Button B to execute its command.
The desired functionality is on click of Button B, while the application window is not active, the application window activates and command associated with Button B is executed. I have also tried removing the command and adding a click handler for test purpose but this displays same behaviour.
I appreciate any help with this issue.
Identified the problem to be related to how our Command binding is setup.
Solution is to fire
CanExecuteChanged eventso that relevantCommandCanExecuteis re-evaluated by the framework. I replaced ourICommandimplementation withPrism DelegateCommandand invokedRaiseCanExecuteChanged()method of delegate command when the condition is changed.Before using Prism DelegateCommand, I tried calling
CommandManager.InvalidateRequerySuggested()but it didn’t help in this case. I have not fully investigated why but we are already using PRISM in other applications so using DelegateCommand will suffice here.Many thanks