I have an issue where when a button is clicked and the process takes a while, the user clicks on other locations on the GUI screen. Those button clicks get queued up in the dispatcher so after the initial button click those other locations get clicked. I want to prevent this from happening so other UI controls don’t get clicked after it’s done processing.
The only solution I can think of is to p/invoke into the mouse events and prevent them from being passed to the application while the button click is being processed. Is this the best approach?
If the process takes a while, it is generally recommended to perform such process in a worker thread, rather than in a GUI thread. So use
BackgroundWorkerapproach like in this CodeProject article, and then useCanExecutemethod of commands associated with specified buttons, like here:WPF Commanding – When do Commands re-evaluate their CanExecute method?
WPF – CanExecute refreshed
EDIT:
You can bind
IsEnabledproperty of your other controls to the result of Command’s CanExecute method.How to disable combobox when command canExecute returns false
How to bind a ComboBoxItem's IsEnabled property to the result of a Command's CanExecute method