TopBottomRuleFormatCondition Class

Represents a top/bottom format condition.

Namespace: DevExpress.Xpf.PivotGrid

Assembly: DevExpress.Xpf.PivotGrid.v21.1.dll


public class TopBottomRuleFormatCondition :


The TopBottomRuleFormatCondition object allows you to find cell values that are above or below the column’s average or find the highest or lowest column values based on a cutoff value.

Conditional Formatting - TopBottom

The TopBottomRuleFormatCondition class is inherited from the FormatConditionBase base class and represents a top/bottom rule format condition. To apply condition formatting, create a new TopBottomRuleFormatCondition instance, specify its parameters and add it to the PivotGridControl.FormatConditions collection.

The type of TopBottomRuleFormatCondition rule is specified by the TopBottomRuleFormatCondition.Rule property. To specify the number or percentage of cells to format, use the TopBottomRuleFormatCondition.Threshold property.

For each condition you can select one of the predefined formats or apply a custom format.

The following code sample shows how to apply the TopBottom format condition with the predefined format and specified rule.

using DevExpress.Xpf.PivotGrid;
using DevExpress.Xpf.Core.ConditionalFormatting;

public MainWindow()
    // ...

    // Creates a new TopBottomRuleFormatCondition instance.
    TopBottomRuleFormatCondition formatRuleTopBottom = new TopBottomRuleFormatCondition();

    // Configures the format condition.
    formatRuleTopBottom.ApplyToSpecificLevel = true;
    formatRuleTopBottom.ColumnName = "fieldQuarter";
    formatRuleTopBottom.RowName = "fieldSalesPerson";
    formatRuleTopBottom.MeasureName = "fieldExtendedPrice";
    formatRuleTopBottom.Rule = TopBottomRule.BottomItems;
    formatRuleTopBottom.Threshold = 10;
    formatRuleTopBottom.PredefinedFormatName = "LightRedFillWithDarkRedText";

    // Adds this instance to the FormatConditionCollection.


This example shows how to add format conditions to WPF Pivot Grid Control.

  • The Data Bar conditional formatting is applied to the ‘Extended Price’ measure and intersection of the ‘Sales Person’ and ‘Quarter’ fields. This condition formats data cells with a predefined orange gradient data bar.
  • The Top Bottom Rule conditional formatting is applied to the ‘Quantity’ measure and intersection of the ‘Sales Person’ and ‘Quarter’ fields. This condition formats data cells whose values are above average with green text and light green fill.
  • The Icon Set conditional formatting is applied to the ‘Extended Price’ measure and intersection of the ‘Sales Person’ and ‘Year’ fields. This condition displays a specific icon in a cell according to the range to which this cell value belongs.

The image below shows the result.

Pivot Grid Conditional Formatting example

View Example

using System.Windows;
using System;
using DevExpress.Xpf.PivotGrid;

namespace WpfPivotGridConditionalFormatting
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        public MainWindow()

            FilterFieldValues(fieldYear, new int[]{2016}, FieldFilterType.Included);

            // Creates a new DataBarFormatCondition instance.
            DataBarFormatCondition formatRulesDataBar = new DataBarFormatCondition();

            // Adds this instance to the FormatConditionCollection.

            // Specifies a column field.
            formatRulesDataBar.ColumnName = "fieldQuarter";

            // Specifies a row field.
            formatRulesDataBar.RowName = "fieldSalesPerson";

            // Specifies a data field.
            formatRulesDataBar.MeasureName = "fieldExtendedPrice";

            // Applies the condition to intersection of row and column fields.
            formatRulesDataBar.ApplyToSpecificLevel = true;

            // Sets the predefined format.
            formatRulesDataBar.PredefinedFormatName = "OrangeGradientDataBar";


        private void FilterFieldValues(PivotGridField field, int[] filterValues, 
            FieldFilterType filterType)
                foreach (object filterValue in filterValues)
                field.FilterValues.FilterType = filterType;
See Also