FormatCondition Class
Represents a conditional format based on a formula.
Namespace: DevExpress.UI.Xaml.Grid
Assembly: DevExpress.UI.Xaml.Grid.v21.2.dll
NuGet Package: DevExpress.Uwp.Controls
Declaration
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.
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:
- Specify the predefined format using the PredefinedFormatName property.
- Set the custom format using the Format property.
- Add the resulting FormatCondition instance to the GridControl.FormatConditions collection.
The XAML snippet below illustrates how to change the font color to green for positive values in the Profit column.
<Grid:GridControl.FormatConditions>
<Grid:FormatCondition FieldName="Profit" Expression="[Profit] >= 0"
PredefinedFormatName="{x:Bind Grid:PredefinedFormatNames.GreenText}"/>
</Grid: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);