CommandTarget 与 Application.Current 的绑定为 null

发布于 2024-10-02 07:51:00 字数 352 浏览 1 评论 0原文

我有一个命令绑定,其 CommandTarget 应该始终是父应用程序。

绑定如下所示:

CommandTarget="{Binding MainWindow, Source={StaticResource Application.Current}}"

但是,CommandTarget永远不会绑定到 MainWindow - 它始终为 null。

因此,事件处理程序的“发送者”会根据调用它的窗口而变化。

Application.Current.MainWindow什么时候会为null?为什么按下按钮时不会重新评估绑定的 CommandTarget?

I have a command binding whose CommandTarget is supposed to always be the parent application.

The binding looks like this:

CommandTarget="{Binding MainWindow, Source={StaticResource Application.Current}}"

However, the CommandTarget is never getting bound to the MainWindow - it's always null.

As a result, the "sender" of the event handler is changing based on which window is calling it.

When would Application.Current.MainWindow be null? Why wouldn't the binding's CommandTarget be re-evaluated when the button is pushed?

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

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

发布评论

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

评论(1

赢得她心 2024-10-09 07:51:00

解决方案是在主窗口的构造函数中创建绑定。

相反,我创建了一个在应用程序加载后触发的事件以初始化多窗口状态。

The solution is that the binding was being created in the Constructor of the MainWindow.

Instead, I created an event to be fired after the application loaded to initialize the multi-window state.

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