Binding Data into a Resource
- by Jordan
How do you bind data from the view model into an object in the resources of the user control? Here is a very abstract example:
<UserControl ...
xmlns:local="clr-namespace:My.Local.Namespace"
Name="userControl">
<UserControl.Resources>
<local:GroupingProvider x:Key="groupingProvider" GroupValue="{Binding ???}" />
</UserControl.Resources>
<Grid>
<local:GroupingConsumer Name="groupingConsumer1" Provider={StaticResource groupingProvider"} />
<local:GroupingConsumer Name="groupingConsumer2" Provider={StaticResource groupingProvider"} />
</Grid>
</UserControl>
How do I bind GroupValue to a property in the view model behind this view. I've tried the following:
<local:GroupingProvider x:Key="groupingProvider" GroupValue="{Binding ElementName=userControl, Path=DataContext.Property}"/>
But this doesn't work.
Edit:
GroupProvider extends DependencyObject and GroupValue is the name of a DependencyProperty. I'm getting an debugging message telling me that the property to which I am binding doesn't exist.