Binding Data into a Resource

Posted by Jordan on Stack Overflow See other posts from Stack Overflow or by Jordan
Published on 2011-02-15T21:48:21Z Indexed on 2011/02/16 15:25 UTC
Read the original article Hit count: 205

Filed under:
|
|

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.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about databinding