WPF DataGrid: Making Image column header into a resource?
-
10-07-2019 - |
Question
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.
Solution
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" ... />
OTHER TIPS
if I wanted a different image for each column?should build a datatemplate For each one of them?
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow