Weird problem where Button does not get re-enabled unless the mouse is clicked

后端 未结 3 1759
时光取名叫无心
时光取名叫无心 2020-12-06 16:08

My app is written using the MVVM pattern in WPF, and all of my Buttons use Command bindings to execute code in my model. All commands have code in CanExecute to determine t

相关标签:
3条回答
  • 2020-12-06 16:45

    My problem seemed to be bound to the Command Binding - I used the RelayCommand as I frequently do but the rendering of a button just wasn't correct until I clicked a window.

    Removing the CanExecute code from the CommandBinding and using an IsEnabled property instead resolved my problem without a head ache - it just took forever until I tried this among so many other things that could have been the problem.

    0 讨论(0)
  • 2020-12-06 16:51

    WPF doesn't update command bound controls unless it has a reason to. Clicking on the GUI causes WPF to refresh so the update then works.

    You can manually cause a refresh of any command bound controls by calling CommandManager.InvalidateRequerySuggested.

    0 讨论(0)
  • 2020-12-06 17:02

    Sometimes, setting the focus on the parent control makes the CommandManager trigger CanExecute. Try the following after setting Running to false:

    ...
    Running = false;
    parentControl.Focusable = true;
    parentControl.Focus();
    
    0 讨论(0)
提交回复
热议问题