Debugging CommandBinding's CanExecute

五迷三道 提交于 2019-12-10 11:28:20

问题


I have a user control with a Button bound to the NavigationCommands.RefreshCommand. The handler for the command is in the parent control. The handler's CanExecute looks like this:

e.CanExecute = !IsConnecting; // IsConnecting is a Dependency Property

For some reason, the Button will remain disabled until I click on the window.

If I click the Button and get it to execute (which causes IsConnecting to temporarily be set to true) it will then disable the button correctly, but won't enable the button until I cause another event in the window (eg. a click).

Are there any tools or tricks I can use to try debug the CanExecute handler of a command which is bound to a button?


回答1:


The button's CanExecute is only called when something happens in the GUI. Since the IsConnecting changes in the background then WPF doesn't update the control.

To force WPF to update the CanExecute call CommandManager.InvalidateRequerySuggested



来源:https://stackoverflow.com/questions/1807255/debugging-commandbindings-canexecute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!