I’ve several DataGrid in my application and they each have the same “template”. For example, here’s how each DataGrid is defined:
<DataGrid Style="{StaticResource MainGridStyle}">
<DataGrid.Columns>
<DataGridTemplateColumn CanUserResize="False"
CanUserSort="False"
CanUserReorder="False"
CellStyle="{StaticResource RightCellStyle}">
...
How could I define the “DataGridTemplateColumn” as a Template in an external resource file, so I would simply have to write something like
<DataGridTemplateColumn Style={StaticResource MyFirstColumn}/>
In the “MainGridStyle” I define properties such “CanUserAddRows”, …
Thx in advance for your help.
Fred
Since
DataGridTemplateColumndoes not have aStyleproperty, one thing you can do is create an attached property.Following is an example :
[NOTE: You may need to change the following code to suit you project.]
Class with an attached property –
Definition of
Style–Use –