Skip to content

DevExpress-Examples/wpf-data-grid-customize-column-headers-based-on-location

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WPF Data Grid - Customize Column Headers Based on Their Location

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.

image

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

Implementation details

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;
}

Files to Review

Documentation

More Examples

About

Apply different settings to column headers based on the header's container.

Topics

Resources

License

Stars

Watchers

Forks