FormatConditionBase.Expression Property
Gets or sets the expression used to apply a conditional format. This is a dependency property.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v24.1.Core.dll
NuGet Package: DevExpress.Wpf.Grid.Core
Declaration
Property Value
Type | Description |
---|---|
String | A String value that specifies the expression used to apply the conditional format. |
Remarks
Use the Expression property to specify a condition for expression based conditional formats (ExpressionConditionBase class descendants). Refer to the Formatting Values Using Custom Conditions topic to learn more.
The Expressions Overview topic contains a list of operators, functions and constants you can use in the expressions.
The code sample below illustrates how to define a conditional format with an expression in markup.
<dxg:TableView.FormatConditions>
<dxg:FormatCondition Expression="Contains([Symbol], 'AT')" FieldName="Symbol" PredefinedFormatName="LightRedFillWithDarkRedText" />
</dxg:TableView.FormatConditions>
The code sample below illustrates how to define the same conditional format in code-behind.
var symbolFormatCondition = new FormatCondition() {
Expression = "Contains([Symbol], 'AT')",
FieldName = "Symbol",
PredefinedFormatName = "LightRedFillWithDarkRedText"
};
view.FormatConditions.Add(symbolFormatCondition);
For indicator-type conditional formats (IndicatorFormatConditionBase class descendants) use the Expression property to specify a complex custom expression that returns a value based on several parameters (e.g., several columns in a row). See the following topics to learn more:
- Formatting Values Using Icon Sets
- Formatting Values Using Color Scales
- Formatting Values Using Data Bars
The following code sample illustrates how to define in markup a conditional format with an expression that returns a value based on NewPrice and OldPrice columns:
<dxg:TableView.FormatConditions>
<dxg:IconSetFormatCondition Expression="Abs([NewPrice] - [OldPrice])" FieldName="Price" PredefinedFormatName="TrafficLights3UnrimmedIconSet"/>
</dxg:TableView.FormatConditions>
The code sample below illustrates how to define the same conditional format in code-behind:
var priceFormatCondition = new IconSetFormatCondition() {
Expression = "Abs([NewPrice] - [OldPrice])",
FieldName = "Price",
PredefinedFormatName = "TrafficLights3UnrimmedIconSet"
};
view.FormatConditions.Add(priceFormatCondition);
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Expression property.
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.