# How to: Apply Conditional Formatting to Data Cells | WPF Controls | DevExpress Documentation

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](/WPF/images/pivot-grid-conditional-formatting-example118543.png)

[View Example](https://github.com/DevExpress-Examples/wpf-pivot-grid-apply-format-conditions-to-data-cells)

- MainWindow.xaml.cs
- MainWindow.xaml
- MainWindow.xaml.vb

<section id="tabpanel_z8iigf8iEE_tabid-csharpMainWindow-xaml-cs" role="tabpanel" data-tab="tabid-csharpMainWindow-xaml-cs">
<pre><code data-code-links="{&quot;/ (System.Windows)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows&quot;,&quot;/ (System)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system&quot;,&quot;/ (DevExpress.Xpf.PivotGrid)(?:;|$)/&quot;:&quot;/WPF/DevExpress.Xpf.PivotGrid&quot;}" class="lang-csharp">using System.Windows;
using System;
using DevExpress.Xpf.PivotGrid;

namespace WpfPivotGridConditionalFormatting
{
    /// &lt;summary&gt;
    /// Interaction logic for MainWindow.xaml
    /// &lt;/summary&gt;
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

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

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

            // Adds this instance to the FormatConditionCollection.
            pivotGridControl1.AddFormatCondition(formatRulesDataBar);

            // Specifies a column field.
            formatRulesDataBar.ColumnName = &quot;fieldQuarter&quot;;

            // Specifies a row field.
            formatRulesDataBar.RowName = &quot;fieldSalesPerson&quot;;

            // Specifies a data field.
            formatRulesDataBar.MeasureName = &quot;fieldExtendedPrice&quot;;

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

            // Sets the predefined format.
            formatRulesDataBar.PredefinedFormatName = &quot;OrangeGradientDataBar&quot;;

        }

        private void FilterFieldValues(PivotGridField field, int[] filterValues, 
            FieldFilterType filterType)
        {
            pivotGridControl1.BeginUpdate();
            try
            {
                field.FilterValues.Clear(); 
                foreach (object filterValue in filterValues)
                    field.FilterValues.Add(filterValue);
            }
            finally
            {
                field.FilterValues.FilterType = filterType;
                pivotGridControl1.EndUpdate();
            }
        }
    }
}
</code></pre></section>
<section id="tabpanel_z8iigf8iEE_tabid-xamlMainWindow-xaml" role="tabpanel" data-tab="tabid-xamlMainWindow-xaml" aria-hidden="true" hidden="hidden">
<pre><code class="lang-xaml">&lt;Window x:Class=&quot;WpfPivotGridConditionalFormatting.MainWindow&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        xmlns:dxpg=&quot;http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid&quot;
        xmlns:dx=&quot;http://schemas.devexpress.com/winfx/2008/xaml/core&quot;
        xmlns:my=&quot;clr-namespace:WpfPivotGridConditionalFormatting.nwindDataSetTableAdapters&quot; 
        xmlns:my1=&quot;clr-namespace:WpfPivotGridConditionalFormatting&quot;
        dx:ThemeManager.Theme=&quot;Office2013LightGray&quot; 
        Title=&quot;Pivot Grid Conditional Formatting&quot; 
        Height=&quot;427&quot; Width=&quot;755&quot; &gt;
    &lt;Window.Resources&gt;
        &lt;dx:TypedSimpleSource x:Key=&quot;TypedSimpleSource&quot; 
                              AdapterType=&quot;my:SalesPersonTableAdapter&quot; 
                              ContextType=&quot;my1:nwindDataSet&quot; 
                              Path=&quot;SalesPerson&quot;&gt;
            &lt;dx:DesignDataManager.DesignData&gt;
                &lt;dx:DesignDataSettings RowCount=&quot;5&quot; /&gt;
            &lt;/dx:DesignDataManager.DesignData&gt;
        &lt;/dx:TypedSimpleSource&gt;
    &lt;/Window.Resources&gt;
    &lt;Grid&gt;
        &lt;dxpg:PivotGridControl Name=&quot;pivotGridControl1&quot; 
                               DataSource=&quot;{Binding Path=Data, Source={StaticResource TypedSimpleSource}}&quot; 
                               AllowConditionalFormattingMenu=&quot;True&quot;&gt;
            &lt;dxpg:PivotGridControl.FormatConditions&gt;
                &lt;dxpg:IconSetFormatCondition ApplyToSpecificLevel=&quot;True&quot; 
                                             MeasureName=&quot;fieldExtendedPrice&quot; 
                                             RowName=&quot;fieldSalesPerson&quot; ColumnName=&quot;fieldYear&quot;&gt;
                    &lt;dxpg:IconSetFormatCondition.Format&gt;
                    &lt;dx:IconSetFormat&gt;
                        &lt;dx:IconSetElement Threshold=&quot;66.666666666666671&quot; ThresholdComparisonType=&quot;GreaterOrEqual&quot;&gt;
                            &lt;dx:IconSetElement.Icon&gt;
                                &lt;BitmapImage UriCachePolicy=&quot;{x:Null}&quot; 
        UriSource=&quot;pack://application:,,,/DevExpress.Xpf.Core.v15.1;component/Core/ConditionalFormatting/Images/IconSets/Arrows3_1.png&quot; /&gt;
                            &lt;/dx:IconSetElement.Icon&gt;
                        &lt;/dx:IconSetElement&gt;
                        &lt;dx:IconSetElement Threshold=&quot;33.333333333333336&quot; ThresholdComparisonType=&quot;GreaterOrEqual&quot;&gt;
                            &lt;dx:IconSetElement.Icon&gt;
                                &lt;BitmapImage UriCachePolicy=&quot;{x:Null}&quot; 
         UriSource=&quot;pack://application:,,,/DevExpress.Xpf.Core.v15.1;component/Core/ConditionalFormatting/Images/IconSets/Arrows3_2.png&quot; /&gt;
                            &lt;/dx:IconSetElement.Icon&gt;
                        &lt;/dx:IconSetElement&gt;
                        &lt;dx:IconSetElement Threshold=&quot;0&quot; ThresholdComparisonType=&quot;GreaterOrEqual&quot;&gt;
                            &lt;dx:IconSetElement.Icon&gt;
                                &lt;BitmapImage UriCachePolicy=&quot;{x:Null}&quot; 
         UriSource=&quot;pack://application:,,,/DevExpress.Xpf.Core.v15.1;component/Core/ConditionalFormatting/Images/IconSets/Arrows3_3.png&quot; /&gt;
                            &lt;/dx:IconSetElement.Icon&gt;
                        &lt;/dx:IconSetElement&gt;
                        &lt;/dx:IconSetFormat&gt;
                    &lt;/dxpg:IconSetFormatCondition.Format&gt;
                &lt;/dxpg:IconSetFormatCondition&gt;
                &lt;dxpg:TopBottomRuleFormatCondition ApplyToSpecificLevel=&quot;True&quot; 
                                                   ColumnName=&quot;fieldQuarter&quot; 
                                                   MeasureName=&quot;fieldQuantity&quot; 
                                                   RowName=&quot;fieldSalesPerson&quot; 
                                                   Rule=&quot;TopItems&quot;&gt;
                    &lt;dxpg:TopBottomRuleFormatCondition.Format&gt;
                        &lt;dx:Format Background=&quot;LightGreen&quot; Foreground=&quot;Green&quot; /&gt;
                    &lt;/dxpg:TopBottomRuleFormatCondition.Format&gt;
                &lt;/dxpg:TopBottomRuleFormatCondition&gt;
            &lt;/dxpg:PivotGridControl.FormatConditions&gt;
            &lt;dxpg:PivotGridControl.Fields&gt;
                &lt;dxpg:PivotGridField Area=&quot;RowArea&quot; FieldName=&quot;Country&quot; 
                                     Name=&quot;fieldCountry&quot; AreaIndex=&quot;0&quot; /&gt;
                &lt;dxpg:PivotGridField Area=&quot;DataArea&quot; FieldName=&quot;Extended Price&quot; 
                                     Name=&quot;fieldExtendedPrice&quot; AreaIndex=&quot;0&quot; /&gt;
                &lt;dxpg:PivotGridField Area=&quot;ColumnArea&quot; Caption=&quot;Year&quot; FieldName=&quot;OrderDate&quot;
                                     Name=&quot;fieldYear&quot; GroupInterval=&quot;DateYear&quot; AreaIndex=&quot;0&quot; /&gt;
                &lt;dxpg:PivotGridField Area=&quot;ColumnArea&quot; Caption=&quot;Quarter&quot; FieldName=&quot;OrderDate&quot; 
                                     Name=&quot;fieldQuarter&quot; GroupInterval=&quot;DateQuarter&quot; AreaIndex=&quot;1&quot; ValueFormat=&quot;Quarter {0}&quot; /&gt;
                &lt;dxpg:PivotGridField Area=&quot;DataArea&quot; FieldName=&quot;Quantity&quot; 
                                     Name=&quot;fieldQuantity&quot; AreaIndex=&quot;1&quot; /&gt;
                &lt;dxpg:PivotGridField Area=&quot;RowArea&quot; FieldName=&quot;Sales Person&quot; 
                                     Name=&quot;fieldSalesPerson&quot; AreaIndex=&quot;1&quot; /&gt;
            &lt;/dxpg:PivotGridControl.Fields&gt;
        &lt;/dxpg:PivotGridControl&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;
</code></pre></section>
<section id="tabpanel_z8iigf8iEE_tabid-vbMainWindow-xaml-vb" role="tabpanel" data-tab="tabid-vbMainWindow-xaml-vb" aria-hidden="true" hidden="hidden">
<pre><code data-code-links="{&quot;/ (System.Windows)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system.windows&quot;,&quot;/ (System)(?:;|$)/&quot;:&quot;https://learn.microsoft.com/dotnet/api/system&quot;,&quot;/ (DevExpress.Xpf.PivotGrid)(?:;|$)/&quot;:&quot;/WPF/DevExpress.Xpf.PivotGrid&quot;}" class="lang-vb">Imports System.Windows
Imports System
Imports DevExpress.Xpf.PivotGrid

Namespace WpfPivotGridConditionalFormatting
    &#39;&#39;&#39; &lt;summary&gt;
    &#39;&#39;&#39; Interaction logic for MainWindow.xaml
    &#39;&#39;&#39; &lt;/summary&gt;
    Partial Public Class MainWindow
        Inherits Window

        Public Sub New()
            InitializeComponent()

            FilterFieldValues(fieldYear, New Integer(){2016}, FieldFilterType.Included)

            &#39; Creates a new DataBarFormatCondition instance.
            Dim formatRulesDataBar As New DataBarFormatCondition()

            &#39; Adds this instance to the FormatConditionCollection.
            pivotGridControl1.AddFormatCondition(formatRulesDataBar)

            &#39; Specifies a column field.
            formatRulesDataBar.ColumnName = &quot;fieldQuarter&quot;

            &#39; Specifies a row field.
            formatRulesDataBar.RowName = &quot;fieldSalesPerson&quot;

            &#39; Specifies a data field.
            formatRulesDataBar.MeasureName = &quot;fieldExtendedPrice&quot;

            &#39; Applies the condition to intersection of row and column fields.
            formatRulesDataBar.ApplyToSpecificLevel = True

            &#39; Sets the predefined format.
            formatRulesDataBar.PredefinedFormatName = &quot;OrangeGradientDataBar&quot;

        End Sub

        Private Sub FilterFieldValues(ByVal field As PivotGridField,
                                      ByVal filterValues() As Integer,
                                      ByVal filterType As FieldFilterType)
            pivotGridControl1.BeginUpdate()
            Try
                field.FilterValues.Clear()
                For Each filterValue As Object In filterValues
                    field.FilterValues.Add(filterValue)
                Next filterValue
            Finally
                field.FilterValues.FilterType = filterType
                pivotGridControl1.EndUpdate()
            End Try
        End Sub
    End Class
End Namespace
</code></pre></section>