Back to Devexpress

FormatCondition Class

wpf-devexpress-dot-xpf-dot-grid-d262fff9.md

latest6.3 KB
Original Source

FormatCondition Class

A value based conditional format.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public class FormatCondition :
    ExpressionConditionBase
vb
Public Class FormatCondition
    Inherits ExpressionConditionBase

Remarks

This conditional format allows you to format cells comparing cell values with static values.

The image below shows a grid column whose Profit cells are red if their values are greater than 10M.

To create this conditional format in code, create the FormatCondition class instance and specify the following settings:

The following code sample illustrates how to define a conditional format in markup:

xaml
<dxg:TableView.FormatConditions>
   <dxg:FormatCondition ValueRule="Greater" Value1="10000000" FieldName="Profit" PredefinedFormatName="LightRedFillWithDarkRedText" />   
</dxg:TableView.FormatConditions>

The code sample below illustrates how to define the same conditional format in code-behind:

csharp
var profitFormatCondition = new FormatCondition() {
   ValueRule = ConditionRule.Greater,
   Value1 = 10000000,
   FieldName = "Profit",
   PredefinedFormatName = "LightRedFillWithDarkRedText"
};
view.FormatConditions.Add(profitFormatCondition);
vb
Dim profitFormatCondition = New FormatCondition() With {
   .ValueRule = ConditionRule.Greater,
   .Value1 = 10000000,
   .FieldName = "Profit",
   .PredefinedFormatName = "LightRedFillWithDarkRedText"
}
view.FormatConditions.Add(profitFormatCondition)

Note

If you use ColumnBase.Binding properties to populate columns with data, their ColumnBase.FieldName property values have the following format: RowData.Row.{Your binding path}.

Refer to the following help topic for more information: How the GridControl Identifies Columns.

The following code snippets (auto-collected from DevExpress Examples) contain references to the FormatCondition class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-data-grid-apply-conditional-formatting/CS/ConditionalFormatting/MainWindow.xaml#L24

xml
<dxg:TopBottomRuleFormatCondition Expression="[Sales]" Rule="TopPercent" Threshold="10" PredefinedFormatName="BoldText"/>
<dxg:FormatCondition Expression="[SalesVsTarget] &lt; 0.0m" FieldName="SalesVsTarget" PredefinedFormatName="RedText"/>
<dxg:FormatCondition Expression="[SalesVsTarget] &gt; 0.0m" FieldName="SalesVsTarget" PredefinedFormatName="GreenText"/>

wpf-data-grid-disable-rows-based-on-their-values/CS/WpfApplication/MainWindow.xaml#L45

xml
<dxg:TableView.FormatConditions>
    <dxg:FormatCondition Expression="![AllowEdit]">
        <dxg:FormatCondition.Format>

wpf-grid-scrollbar-annotations/CS/WpfApplication25/MainWindow.xaml#L31

xml
<dxg:TableView.FormatConditions>
    <dxg:FormatCondition Expression="[Number] &gt; 2.0m and [Number] &lt; 4.0m" FieldName="Number" ApplyToRow="True">
        <dx:Format Background="Green"/>

Inheritance

Object DispatcherObject DependencyObject FormatConditionBase ExpressionConditionBase FormatCondition

See Also

FormatCondition Members

Conditional Formats

Formatting Values Using Comparison Rules

Formatting Date-Time Values

Formatting Values Using Custom Conditions

DevExpress.Xpf.Grid Namespace