CommandTarget bindings to Application.Current is null
I have a command 开发者_Go百科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?
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.
精彩评论