views:

69

answers:

1

Take this scenario where I am working with a grid like control:

<RadGrid DataContext={Binding someDataContextObject, Mode=OneWay}>
   <RadGrid.columns>
      <RadGrid.Column Header="Column Header"
                            DataMember="{Binding dataContextObjectProperty, Mode=OneWay}">
           [...]
           <DataTemplate>
                <MyCustomControl Data="{Binding ???}" />
           </DataTemplate>
      <\RadGrid.Column>
   </RadGrid.columns>   
</RadGrid>

I would like to bind the Data dependency property of MyCustomControl to the DataMember dependency property of the column to avoid multiple bindings to the same data. How do I do it?

A: 

It seems that there is not easy way to accomplish that task. The problem is that it is not possible to bind something inside of DataTemplate to something that is outside the data template. You could find some kind of workaround here.

However I don't think this deserves that kind of effort. What is the problem having multiple bindings to the same data?

As they say If something is so difficult may be you doing it the wrong way. Do you really needs to bind your custom control to the whole data context? Basically when you give the grid the data source it will take care to pick a single row from your data context and set it as DataContext for your template. However if you have a good reason doing it that way you should check out the link from the first paragraph.

Hope this helps!

Koynov