views:

819

answers:

2

I have created a checkbox column in a WPF DataGrid, and I have set the column header to be a checkmark image. Here is my markup:

<toolkit:DataGridCheckBoxColumn  Binding="{Binding Completed}" Width="25" IsReadOnly="false" >
    <toolkit:DataGridCheckBoxColumn.Header>
        <Image Source="..\Resources\Images\checkmark.png" Height="9" Width="9" Margin="3,0,0,0" />
    </toolkit:DataGridCheckBoxColumn.Header>
</toolkit:DataGridCheckBoxColumn>

I would like to convert that header into a resource (for example, "CheckmarkHeader", so that I can invoke it in other grids using a data grid column's HeaderStyle property--something like this:

<toolkit:DataGridCheckBoxColumn ... HeaderStyle="CheckmarkHeader ... />

Can that be done? How would I do it? Thanks for your help.

A: 

Does it have to be HeaderStyle? Using HeaderTemplate with a DataTemplate like so seems to work:

<Window.Resources>
    <DataTemplate x:Key="CheckMarkTemplate">
        <Image Source="..\Resources\Images\checkmark.png" Height="9" Width="9" Margin="3,0,0,0" />
    </DataTemplate>
</Window.Resources>
...
<toolkit:DataGridCheckBoxColumn ... HeaderTemplate="CheckMarkTemplate" ... />
Joseph Sturtevant
That works great--thanks!
David Veeneman
A: 

if I wanted a different image for each column?should build a datatemplate For each one of them?

Michele