I'm evaluating the RadGridView as a possible data grid for a project I am working on. One of the things I need the grid to do is to use custom controls to display and edit the contents of cells. I can do this with the CellTemplate and CellEditTemplate like so:
<controls:GridViewDataColumn Header="Field 1"> |
<controls:GridViewDataColumn.CellTemplate> |
<DataTemplate> |
<my:CustomControl Text="{Binding Field1}"/> |
</DataTemplate> |
</controls:GridViewDataColumn.CellTemplate> |
</controls:GridViewDataColumn> |
The CellEditTemplate works similarly. This code works fine. However, it is not very maintainable. If I have 20 columns in my table that all use those same custom controls, I have to have 20 copies of this code, with only the field name changing. If I need to change that template, such as to add a property setting to my:CustomControl, I have to edit all 20 of those copies.
What I would like to do is make that DataTemplate a shared resource. I have been able to do something like this with some of the other grids I've tried, but I haven't figured out how to do it with RadGridView yet. Obviously hard-coding {Binding Field1} isn't going to work, but I don't know what binding I need to put in there to make it bind to whatever the GridViewDataColumn is bound to. I know I can bind a column to a field by doing the following:
<controls:GridViewDataColumn Header="Field 1" DataMemberBinding="{Binding Field1}"/> |
This works as well, if I don't want to use my custom controls. I'm just not sure how to write the DataTemplates in such a way that they bind to whatever that DataMemberBinding is set to.
If this is possible, please let me know so that I can continue my evaluation of the control.
Thanks,
Jason