Reputation: 12295
Hi I have 2 UserControls. Parent UserControl and Child UserControl and both have their own ViewModel. How can I bind Parent Control's Dependency Property to the Property in the ViewModel of Child Control. Any help will be appericiable. I can easily bind the Parent UserControl DependencyProperty to the Child Control Dependency Property . But the problem is how to bind it to ViewModel Property. Suppose I bind Tag Property of Child UserControl to the Dependency Property of ParentControl(upto here its fine) but now how I can Bind this Tag Property to the ViewModel Property.(I want to keep it simple and don't want to use Converter/Converter Parameter logic).Thanks in advance.
Upvotes: 0
Views: 3102
Reputation: 132548
Typically your ViewModels
are the DataContext
(Data Layer) of your UserControls
, so you can access the ViewModel
of the child control by binding to the DataContext
property
{Binding ElementName=MyChildUserControl, Path=DataContext.ChildViewModelProperty}
Upvotes: 2
Reputation: 9871
try something like
{Binding Path=PathToParentDP, RelativeSource={RelativeSource AncestorType={x:Type ParentType}}}
Upvotes: 2