[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Implementation Details
   [Expand]Grid View Data Layout
   [Expand]Binding to Data
   [Expand]Master-Detail Data Representation
   [Expand]Data Editing and Validation
   [Expand]Filtering and Searching
   [Expand]Data Summaries
   [Expand]Paging and Scrolling
   [Expand]Focus, Navigation, Selection
   [Expand]Conditional Formatting
   [Expand]Appearance Customization
   [Collapse]MVVM Enhancements
     Binding to a Collection of Columns
     Binding to Total and Group Summaries
     Binding to a Collection of Bands
     Binding to a Collection of Conditional Formatting Rules
   [Expand]Printing and Exporting
   [Expand]Performance Improvement
   [Expand]Design-Time Features
   [Expand]Visual Elements
   [Expand]End-User Capabilities
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Binding to a Collection of Conditional Formatting Rules

When engineering a WPF application using the Model View ViewModel (MVVM) architectural pattern, you may be required to describe conditional formatting rules in a Model or ViewModel. The grid can be bound to a collection of objects containing conditional formatting rules, described in a Model or ViewModel, thus minimizing the need for 'code-behind'.

Expanded View Model Implementation

The example used in this topic contains a view model code that includes the following classes.

  • Order - a data object that contains order information (e.g., quantity, discount, etc.).
  • ViewModel - the order view model. The ViewModel exposes the Orders property (a list of orders displayed within the grid) and the Rules property (a list of formatting rules).
  • OrderData - supplies order information to be displayed within the grid control.
  • FormattingRule - describes a conditional formatting rule. This class provides properties that correspond to settings common to all types of conditional formatting rules.
  • FormattingType - enumerates possible types of applied formattings.

If the format conditions collection might be changed after it has been assigned to the grid control, it should implement INotifyCollectionChanged, so that changes made within a View Model are automatically reflected by the grid.

Expanded Format Condition Templates and Selector

The GridControl generates condition formattings based on condition formattings templates. Create multiple templates, one template for each condition formatting type. Using a single template, you can create an unlimited number of condition formattings in unlimited number of grid controls. In this example, there are three condition formatting templates: FontFormat, BackgroundFormat, and IconFormat.

To avoid performance issues when binding to column properties, use the dxci:DependencyObjectExtensions.DataContext attached property. See the example below.

To choose the required template based on the column's type, use the Template Selector. In this example, the template selector is represented by the FormatConditionSelector class.


If all conditional formattings can be described using a single template, you have no need to create a template selector. Instead, assign this template to the grid View's TableView.FormatConditionGeneratorTemplate (TreeListView.FormatConditionGeneratorTemplate for the TreeListView) property.

Expanded Customizing the GridControl

Finally, specify the grid View's FormatConditionGeneratorTemplateSelector and FormatConditionsSource properties. The TableView.FormatConditionsSource (TreeListView.FormatConditionsSource) property specifies the source from which the grid generates conditional formattings. The TableView.FormatConditionGeneratorTemplateSelector (TreeListView.FormatConditionGeneratorTemplateSelector) property specifies the template selector, which returns a template for each conditional formatting based on its type.

The image below shows the result.

Is this topic helpful?​​​​​​​