Template for DataGrid.Columns?

Sep 4, 2009 at 7:53 AM

Hi, can anyone help me - I have some classes that are quite similar and I would like to template the columns they share, For example

class Base { public string A { get; set; } }
class B : Base { public string B { get; set; } }
class C : Base { public string C { get; set; } }

I am trying to create a sort of template DataGrid so I can just extent it with one extra column for each of the derived classes. Is there some way I can do this in XAML?

Thanks, Z

Sep 4, 2009 at 8:27 PM

Hi zeryk,

We're unclear what the scenario is here.  Could you please be more specific?


Saied K.

Sep 5, 2009 at 9:44 AM
Edited Sep 5, 2009 at 9:44 AM

Hi Saied, thanks for responding. From above, I would create a datagrid with the A column which is used by both classes

<Datagrid.Columns><DataGridTextColumn Header="A" Binding={Binding Path=A}"/></Datagrid.Columns>

and for the derived classes B and C I want to "inherit" those column definitions, eg for class B

<Datagrid.Columns NotSureHowToInclude="SharedColumnsAbove">
<DataGridTextColumn Header="B" Binding={Binding Path=B}"/>

I realise it can't be done like that but that's what I'm trying to achieve. Is there another way?


Sep 8, 2009 at 1:53 PM

You cannot really share columns in this way.  The best that you can do is setup a style that they inherit.  Would that suffice?