Articles in this section
Category / Section

How to apply conditional format style on Property change?

1 min read

The WPF GridDataControl has built-in support for conditional formatting. This feature allows you to format cells and rows based on a certain condition. This can be achieved by setting GridDataControl.ConditionalFormats property. ConditionalFormats is a collection property where you can add any number of conditions using GridDataConditionalFormat.

GridDataConditionalFormat has two properties, namely: Style, that is GridDataStyleInfo and Conditions, that is FreezableCollection of GridDataCondition. When the specified conditions are fulfilled, the given style is applied to the cell or row based on AppylStyleToColumn. If ApplyStyleToColumn is True, the style is applied to that particular cell that matches the conditions. Otherwise, the style is applied to the row.

Here, GridDataConditionlFormat is defined for “Total” column and ApplyStyleToColumn is False. So the specified style is applied to the row.

 

XAML

<syncfusion:GridDataControl x:Name="gdc"> 
              <syncfusion:GridDataConditionalFormat Name="C15" 
                                                          ApplyStyleToColumn="false">
                        <syncfusion:GridDataConditionalFormat.Style>
                            <syncfusion:GridDataStyleInfo Background="Orange" />
                        </syncfusion:GridDataConditionalFormat.Style>
                        <syncfusion:GridDataConditionalFormat.Conditions>
                            <syncfusion:GridDataCondition ColumnName="Total"
                                                          ConditionType="LessThan"
                                                          Value="1000000" />
                        </syncfusion:GridDataConditionalFormat.Conditions>
                    </syncfusion:GridDataConditionalFormat>
</syncfusion:GridDataControl>

When data updates come from underlying data, the specific cells alone get refreshed in UI, for better performance reasons. So when you specify GridDataConditionalFormat for a row, the specific cells alone get refreshed, based on the style specified in GridDataConditionalFormat. You can refresh the row by setting GridDataControl.Model.RefreshWholeRow property to True, as shown in the following code snippet,

 

C#

this.gdc.Model.RefreshWholeRow = true;

In the following screenshot, the style is applied to the row based on Total column values as specified in the GridDataConditionalFormat. When the Total column value changes at runtime, the Row is refreshed, as you have set the GridDataControl.Model.RefreshWholeRow property to True.

 

Conclusion

I hope you enjoyed learning about how to apply conditional format conditional style on property change.

You can refer to our WPF GridDataControl feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF GridDataControl example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied