CommandTarget 与 Application.Current 的绑定为 null
我有一个命令绑定,其 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是在主窗口的构造函数中创建绑定。
相反,我创建了一个在应用程序加载后触发的事件以初始化多窗口状态。
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.