This example applies different settings to column headers based on the header's container. The GridControl displays column headers in the column header panel, group panel (if you group data by this column), or column chooser. Use the ColumnBase.HeaderPresenterType attached property to determine the header's location.
The following table demonstrates how the header's text is changed:
Header's Location | New Text |
---|---|
Column header panel | Custom Panel Header |
Group panel | Custom Group Header |
Column chooser | Custom Column Chooser Header |
This solution implements a multi-value converter that changes the header's text. The converter receives the column header and its location and returns the new header text:
<Style TargetType="dxg:GridColumn">
<Setter Property="HeaderTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{local:CustomHeaderConverter}">
<Binding />
<Binding Path="(dxg:ColumnBase.HeaderPresenterType)"
RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
private string GetCustomHeaderString(string originalHeader, HeaderPresenterType headerType) {
switch (headerType) {
case HeaderPresenterType.Headers:
return originalHeader.Replace("Original ", "Custom\nPanel\n");
case HeaderPresenterType.GroupPanel:
return originalHeader.Replace("Original", "Custom Group");
case HeaderPresenterType.ColumnChooser:
return originalHeader.Replace("Original", "Custom Column Chooser");
}
return originalHeader;
}