Back to Devexpress

Customize Pivot Grid Colors

wpf-11213-controls-and-libraries-pivot-grid-appearance-customizing-pivot-grid-colors.md

latest8.8 KB
Original Source

Customize Pivot Grid Colors

  • Jan 16, 2024
  • 3 minutes to read

This topic lists properties you can use to change the color of the PivotGridControl’s elements.

Set these properties directly or create a style that targets the PivotGridControl and specify the colors.

Standard Control Properties

You can use the Control properties to change the color of the PivotGridControl’s elements:

PivotGridControl Properties

You can use the PivotGridControl properties to change the colors of cell and field values.

PropertyDescription
CellBackgroundGets or sets the brush used to paint the background of data cells. This is a dependency property.
CellForegroundGets or sets the brush used to paint the foreground of data cells. This is a dependency property.
CellSelectedBackgroundGets or sets the brush used to paint the background of the selected data cell. This is a dependency property.
CellSelectedForegroundGets or sets the brush used to paint the foreground of the selected data cell. This is a dependency property.
CellTotalBackgroundGets or sets the brush used to paint the background of total and grand total cells. This is a dependency property.
CellTotalForegroundGets or sets the brush used to paint the foreground of total and grand total cells. This is a dependency property.
CellTotalSelectedBackgroundGets or sets the brush used to paint the background of the selected total or grand total cell. This is a dependency property.
CellTotalSelectedForegroundGets or sets the brush used to paint the foreground of the selected total or grand total cell. This is a dependency property.
ValueBackgroundGets or sets the brush used to paint the background of field value cells. This is a dependency property.
ValueForegroundGets or sets the brush used to paint the foreground of field value cells. This is a dependency property.
ValueSelectedBackgroundGets or sets the brush used to paint the background of the selected field value cell. This is a dependency property.
ValueSelectedForegroundGets or sets the brush used to paint the foreground of the selected field value cell. This is a dependency property.
ValueTotalBackgroundGets or sets the brush used to paint the background of total and grand total headers. This is a dependency property.
ValueTotalForegroundGets or sets the brush used to paint the foreground of total and grand total headers. This is a dependency property.
ValueTotalSelectedBackgroundGets or sets the brush used to paint the background of the selected total or grand total header. This is a dependency property.
ValueTotalSelectedForegroundGets or sets the brush used to paint the foreground of the selected total or grand total header. This is a dependency property.

The following example demonstrates how to create a custom style for a pivot grid.

In this example, we create and apply a style that sets custom colors for pivot grid cells and field values.

The following image shows the result:

xaml
<Window xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="DXPivotGrid_CustomizeBrushes.MainWindow"
        dx:ThemeManager.ThemeName="Office2010Black"
        Height="600" Width="800"
        Title="Main Window">
    <Grid>
        <Grid.Resources>
            <Style x:Key="pivotGridCustomStyle" TargetType="dxpg:PivotGridControl">
                <Setter Property="CellBackground" Value="#b4c7ff"/>
                <Setter Property="CellForeground" Value="Black"/>
                <Setter Property="CellSelectedBackground" Value="#888ea0"/>
                <Setter Property="CellSelectedForeground" Value="White"/>
                <Setter Property="CellTotalBackground" Value="#7599ff"/>
                <Setter Property="CellTotalForeground" Value="Black"/>
                <Setter Property="CellTotalSelectedBackground" Value="#51555f"/>
                <Setter Property="CellTotalSelectedForeground" Value="White"/>
                <Setter Property="ValueBackground" Value="#f3dfaa"/>
                <Setter Property="ValueForeground" Value="Black"/>
                <Setter Property="ValueSelectedBackground" Value="#888ea0"/>
                <Setter Property="ValueSelectedForeground" Value="White"/>
                <Setter Property="ValueTotalBackground" Value="#f1c44a"/>
                <Setter Property="ValueTotalForeground" Value="Black"/>
                <Setter Property="ValueTotalSelectedBackground" Value="#51555f"/>
                <Setter Property="ValueTotalSelectedForeground" Value="White"/>
            </Style>
        </Grid.Resources>
        <dxpg:PivotGridControl Style="{StaticResource ResourceKey=pivotGridCustomStyle}"
                               Name="pivotGridControl1" >
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField Name="fieldYear" FieldName="OrderDate" Area="ColumnArea"
                                     Caption="Year" GroupInterval="DateYear"/>
                <dxpg:PivotGridField Name="fieldCategoryName" FieldName="CategoryName"
                                     Area="RowArea" Caption="Category"/>
                <dxpg:PivotGridField Name="fieldProductName" FieldName="ProductName"
                                     Area="RowArea" Caption="Product"/>
                <dxpg:PivotGridField Name="fieldQuantity" FieldName="Quantity" Area="DataArea"/>
            </dxpg:PivotGridControl.Fields>
        </dxpg:PivotGridControl>
    </Grid>
</Window>