CanExecute 方法出现 false 问题

发布于 2024-09-16 10:25:10 字数 350 浏览 2 评论 0原文

嗯,在我们的应用程序中,这通常工作得很好。但在某些时候,没有任何 CanExecute 方法触发(即使我显式调用 CommandManager.InvalidateRequerySuggested(),CanExecute 方法也不会运行)。不管怎样,尽管它们没有运行,但它们都被设置为 false,因此绑定到 CommandBinding 的每个按钮、菜单项等都会被禁用,直到我单击 MainWindow。

现在,我怀疑另一个窗口导致了这种情况,当我们执行某个操作时,会弹出一个窗口,然后在下一个操作之后,所有按钮都会被禁用,而无需通过 CanExecute 方法。

有人见过这样的行为吗?非常感谢任何有关如何解决此问题的建议。

谢谢。

Well, in our application this usually works fine. But at some point, none of the CanExecute methods fire (even if I explicitly call CommandManager.InvalidateRequerySuggested(), the CanExecute methods don't run). Anyway, despite the fact that they don't run, they all get set to false, so every button, menu item, etc, bound to a CommandBinding, gets disabled until I click the MainWindow.

Now, I suspect another Window causing this, when we do a certain action, a Window pops up, and then after the next action, all the buttons become disabled, without going through the CanExecute method.

Has anyone seen such a behavior? Any suggestion on how to solve this, is greatly appreciated.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

秋日私语 2024-09-23 10:25:10

修好了。它与我提到的另一个窗口有关,但事实并非如此。问题是我们有一种方法来隐藏提到的窗口,在该方法中,我们将焦点返回到主窗口,这就是问题所在。不知道如何或为什么,但删除

App.MainWindow.Focus()

线路解决了这个问题。因此,每当您关闭或隐藏子窗口时,请勿在主窗口上调用 Focus() 方法。

谢谢!

Fixed it. It was related to the other window I mentioned, but it wasn't exactly that. The problem was that we had a method to hide the mentioned window, in that method, we gave focus back to the main window, and THAT was the problem. Not sure how or why, but removing the

App.MainWindow.Focus()

Line fixed this problem. So, whenever you close or hide a child window, do not call the Focus() method on your Main one.

Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文