Skip to main content
A newer version of this page is available. .

PivotGridControl.FieldHeaderTemplateSelector Property

Gets or sets an object that chooses a field header template based on custom logic. This is a dependency property.

Namespace: DevExpress.Xpf.PivotGrid

Assembly: DevExpress.Xpf.PivotGrid.v19.2.dll

Declaration

public DataTemplateSelector FieldHeaderTemplateSelector { get; set; }

Property Value

Type Description
DataTemplateSelector

A DataTemplateSelector descendant that chooses a template based on custom logic.

Remarks

A template that defines the presentation of field headers is specified by the PivotGridControl.FieldHeaderTemplate property. If you have more than one template that can be used to render field headers, you can implement custom logic to choose the required template. To do this, derive from the DataTemplateSelector class, implement the SelectTemplate method that returns a template which meets the required condition, and assign an instance of this class to the FieldHeaderTemplateSelector property.

The FieldHeaderTemplateSelector is used for those fields whose PivotGridField.HeaderTemplateSelector property is not specified.

The FieldHeaderTemplateSelector is in effect only if the PivotGridControl.FieldHeaderTemplate property is set to null (Nothing in Visual Basic). Otherwise, the PivotGridControl.FieldHeaderTemplate template is used.

To specify template selectors that define templates used to display a field headers in the Customization Form, use the PivotGridControl.FieldHeaderListTemplateSelector and PivotGridControl.FieldHeaderTreeViewTemplateSelector properties.

Example

The following example demonstrates how to select the cell template based on custom logic.In this example, data cell values are represented by progress bars. The template used to display the data cells is selected based on the share of the data cell value in the Row Grand Total value. If this share is bigger than 80% or less than 20%, a red progress bar is displayed in the cell. Otherwise, a blue bar is displayed.

<Window x:Class="DXPivotGrid_SelectingCellTemplate.MainWindow"
        xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:core="http://schemas.devexpress.com/winfx/2008/xaml/core"
        xmlns:local="clr-namespace:DXPivotGrid_SelectingCellTemplate"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="230" Width="725">
    <Window.Resources>
        <DataTemplate x:Key="NormalCellTemplate">
            <ProgressBar Foreground="Blue" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  
             Maximum="{Binding Path=RowTotalValue, Mode=OneWay, Converter={local:RoundConverter}}"
             Value="{Binding Path=Value, Mode=OneWay, Converter={local:RoundConverter}}"
             core:ThemeManager.ThemeName="Office2007Silver" Minimum="0" Margin="3"/>
        </DataTemplate>
        <DataTemplate x:Key="HighlightedCellTemplate">
            <ProgressBar Foreground="Red" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  
             Maximum="{Binding Path=RowTotalValue, Mode=OneWay, Converter={local:RoundConverter}}"
             Value="{Binding Path=Value, Mode=OneWay, Converter={local:RoundConverter}}"
             core:ThemeManager.ThemeName="Office2007Silver" Minimum="0" Margin="3"/>
        </DataTemplate>
        <DataTemplate x:Key="DefaultCellTemplate">
            <TextBlock Text="{Binding Path=Value}" HorizontalAlignment="Right"
                       VerticalAlignment="Center" Margin="5"/>
        </DataTemplate>
    </Window.Resources>
    <Grid>
        <dxpg:PivotGridControl x:Name="picotGridControl1" FieldCellTemplate="{x:Null}">
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField Name="fieldCountry" FieldName="Country" Area="RowArea"/>
                <dxpg:PivotGridField Name="fieldYear" FieldName="OrderDate" Area="ColumnArea"
                                     Caption="Year" GroupInterval="DateYear"/>
                <dxpg:PivotGridField Name="fieldMonth" FieldName="OrderDate" Area="ColumnArea"
                                     Caption="Month" GroupInterval="DateMonth"/>
                <dxpg:PivotGridField Name="fieldQuantity" FieldName="Quantity" Area="DataArea"/>
            </dxpg:PivotGridControl.Fields>
            <dxpg:PivotGridControl.FieldCellTemplateSelector>
                <local:CellTemplateSelector/>
            </dxpg:PivotGridControl.FieldCellTemplateSelector>
        </dxpg:PivotGridControl>
    </Grid>
</Window>
See Also