I made a class inheriting from datagridcolumnheader. I styled it (using for now the default style of the original datagridcolumnheader) But I dont know how to force my columns to use this customDatagridcolumnHeader.
I tried this :
<DataGridTextColumn Binding="{Binding Donateur}" Width="*">
<DataGridTextColumn.Header>
<local:CustomDatagridColumnHeader/>
</DataGridTextColumn.Header>
</DataGridTextColumn>
It's not working, and I understand why. How to do something like that ? I tried to modify the default DatagridColumnHeadersPresenter, but it has only two pars, the PART_FillerColumnHeader (which I CAN replace) and the itemsPresenter. The purpose is to add property, function and events on the new class (Just trying to have textboxes for filter, but not for all columns, and not for all datagrid). I "think" I can find a way to make it by inheriting directly the datagrid, and then finding via the tree the textboxes, but that's not very practical for all the things I want to do (like hiding the textbox for one column)
EDIT : Here is the future template
<Style TargetType="local:RafDatagridColumnHeader">
<Style.Resources>
<local:IsNotNothingConverter x:Key="IsNotNothingConverter"/>
<local:IsNotNothingToVisibilityConverter x:Key="IsNotNothingToVisibilityConverter"/>
</Style.Resources>
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding}" VerticalAlignment="Center"></TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:RafDatagridColumnHeader">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Visibility="{Binding Column, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:RafDatagridColumnHeader}, Converter={StaticResource IsNotNothingToVisibilityConverter}}">
<TextBox HorizontalAlignment="Stretch" Margin="3"/>
</Grid>
<theme:DataGridHeaderBorder Grid.Row="1" SortDirection="{TemplateBinding SortDirection}"
IsHovered="{TemplateBinding IsMouseOver}"
IsPressed="{TemplateBinding IsPressed}"
IsClickable="{TemplateBinding CanUserSort}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding ="{TemplateBinding Padding}"
SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
SeparatorBrush="{TemplateBinding SeparatorBrush}" VerticalAlignment="Stretch">
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
RecognizesAccessKey="True" />
</theme:DataGridHeaderBorder>
<Thumb x:Name="PART_LeftHeaderGripper" Grid.Row="1"
HorizontalAlignment="Left"
Style="{StaticResource ColumnHeaderGripperStyle}"/>
<Thumb x:Name="PART_RightHeaderGripper" Grid.Row="1"
HorizontalAlignment="Right"
Style="{StaticResource ColumnHeaderGripperStyle}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
If I modify the control DataTemplate instead of the templaet itself, I will lose all the good stuff of the columnheader (sorting, sorting glyph, thumbs to change width, reordering...) Well, in fact, I will not, but the textbox will be INSIDE the header, and the sort glyph will be on top... By the way I did it, it's nicer and more readable