本文介绍了调试的CommandBinding的CanExecute的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮绑定到 NavigationCommands.RefreshCommand 用户控件。该处理程序命令在父控件。该处理程序的 CanExecute 是这样的:

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.

如果我点击按钮,并得到它来执行(这会导致 IsConnecting 来临时设置为true)那么它会正确地关闭按钮,但不会启用按钮,直到我造成另一个事件窗口(如点击)。

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).

是否有任何工具或技巧,我可以用它来尝试调试它绑定到一个按钮命令的CanExecute处理?

推荐答案

当事情发生在GUI按钮的CanExecute只调用。由于IsConnecting改变在后台然后WPF不更新控制

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.

要强制WPF更新CanExecute呼叫 CommandManager.InvalidateRequerySuggested

To force WPF to update the CanExecute call CommandManager.InvalidateRequerySuggested

这篇关于调试的CommandBinding的CanExecute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 16:35
查看更多