.net - 调试 CommandBinding 的 CanExecute

标签 .net wpf button commandbinding

我有一个用户控件,其 Button 绑定(bind)到 NavigationCommands.RefreshCommand。命令的处理程序位于父控件中。处理程序的 CanExecute 如下所示:

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

由于某种原因,按钮将保持禁用状态,直到我单击该窗口。

如果我单击 Button 并让它执行(这会导致 IsConnecting 暂时设置为 true),它将正确禁用该按钮,但不会启用该按钮,直到我在窗口中引发另一个事件(例如单击)。

我可以使用任何工具或技巧来尝试调试绑定(bind)到按钮的命令的 CanExecute 处理程序吗?

最佳答案

仅当 GUI 中发生某些情况时才会调用按钮的 CanExecute。由于 IsConnecting 在后台发生更改,因此 WPF 不会更新控件。

强制 WPF 更新 CanExecute 调用 CommandManager.InvalidateRequerySuggested

关于.net - 调试 CommandBinding 的 CanExecute,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1807255/

相关文章:

c# - 将 ImageMagick 和 GhostScript 与 nuget 结合使用

.net - Visual Studio 2010的源代码大纲窗口

c# - 我怎样才能得到任何特定的过程窗口大小?

c# - ORM 与 CodeContracts 结合使用的实体 - 确保不变量

c# - 如何通过样式设置事件函数?

c# - 当绑定(bind)属性声明为接口(interface)类型与类类型时,WPF 绑定(bind)行为不同?

.net - 在 XAML 中有没有办法将 UpdateSourceTrigger 默认为 PropertyChanged?

html - 按钮的渐变不起作用

NIH 网站上的 Python Mechanize 提交按钮

android - 通过单击按钮更改两个不同的背景