Вопрос

The current data context is SomeViewModel but I need to bind to a property on the view model of the main window. Im guessing I need to specify Source or RelativeSource in the binding but not quite sure how to manage that. The MainWindowViewModel is the data context of the main window (and is also a public member). Any guidance most welcome!

Это было полезно?

Решение

Try something like

{Binding Path=DataContext.YourMainWindowViewModelPropertyName, 
         RelativeSource={RelativeSource AncestorType={x:Type Window}}}

It should work if your main window is instance of Window type, and your current "object" is sub-UserControl.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top