Skip to main content

FormatCondition Class

Represents a conditional format based on a formula.

Namespace: DevExpress.WinUI.Grid

Assembly: DevExpress.WinUI.Grid.v23.2.dll

NuGet Package: DevExpress.WinUI

Declaration

[ContentProperty(Name = "Format")]
public class FormatCondition :
    FormatConditionBase

Remarks

This conditional format allows you to format cells based on comparison of cell values.

The image below shows a grid column whose Profit cells are green if their values are positive.

DevExpress WinUI Grid - Format Conditions

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

  • Specify the comparison logic in one of the following ways:

    • Specify the ValueRule, Value1 (and Value2 for Between rule) properties to define how cell values should be compared to boundary value(s).
    • Specify the custom expression by setting the Expression property.
  • Use the FieldName property to specify the column’s field name to which to apply the conditional format.
  • Specify the target cells’ formatting in one of the following ways:

  • Add the resulting FormatCondition instance to the DataControlBase.FormatConditions collection.

The XAML snippet below illustrates how to change the font color to green for positive values in the Profit column.

<dxg:GridControl.FormatConditions>
    <dxg:FormatCondition FieldName="Profit" Expression="[Profit] &gt; 0" PredefinedFormatName="GreenText"/>
</dxg:GridControl.FormatConditions>

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

var profitFormatCondition = new FormatCondition() {
    FieldName = "Profit",
    Expression = "[Profit] > 0",
    PredefinedFormatName = "GreenText"
};
gridControl.FormatConditions.Add(profitFormatCondition);

Inheritance

See Also