Reputation: 6296
I'm creating a form using WPF with MVVM.
There I have my View with its DataSource bound to my ViewModel object. Great.
In my xaml, I have an ItemsControl with its ItemSource bound to ViewModel.MyCollectionOfFoo.
For every Foo object in this collection, I'm creating a control with bindings to this foo object, but I also need to bind a Command to every one of them.
This Command is a property of my ViewModel object (witch is the DataSource of the View).
Since I'm inside the ItemsControl, how to get the reference to the ViewModel.DoSomethingCommand?
It's like binding to a property of another's control binding...
Thanks,
André Carlucci
Upvotes: 2
Views: 1534
Reputation: 172270
<... Command="{Binding Path=DataContext.CommandPropertyOfYourViewModel,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type Window}}}">
This will use the DataContext of your Window as the binding source instead of the current DataContext.
Upvotes: 6