Skip to main content
A newer version of this page is available. .

TableView.FormatConditionGeneratorTemplateSelector Property

Gets or sets the format condition template selector. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v21.1.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public DataTemplateSelector FormatConditionGeneratorTemplateSelector { get; set; }

Property Value

Type Description
DataTemplateSelector

A format condition template selector.

Remarks

You can define conditional formatting rules in a ViewModel and apply them to the GridControl. To do this, follow the steps below:

  1. Create a collection of conditional formatting rules in a ViewModel and specify a data template that generates format conditions.

  2. Assign the conditional formatting rule collection to the TableView.FormatConditionsSource property and the format condition template to the TableView.FormatConditionGeneratorTemplate property:

If you have multiple format condition templates, implement custom logic to choose a template:

  1. Create a template selector – a class that chooses a template based on a condition. This class should be derived from the DataTemplateSelector class.
  2. Override the SelectTemplate method to return a template that meets the condition.
  3. Assign an instance of the template selector class to the FormatConditionGeneratorTemplateSelector property.
<Window.Resources>
    <!-- ... -->
    <local:FormatConditionSelector x:Key="FormatConditionSelector" 
                                   BackgroundTemplate="{StaticResource BackgroundTemplate}" 
                                   FontTemplate="{StaticResource FontTemplate}" 
                                   IconTemplate="{StaticResource IconTemplate}"/>
</Window.Resources>
<dxg:GridControl ItemsSource="{Binding Orders}">
    <!-- ... -->
    <dxg:GridControl.View>
        <dxg:TableView FormatConditionsSource="{Binding Rules}"
                       FormatConditionGeneratorTemplateSelector="{StaticResource FormatConditionSelector}"/>
    </dxg:GridControl.View>
</dxg:GridControl>
public class FormatConditionSelector : DataTemplateSelector {

    public DataTemplate BackgroundTemplate { get; set; }
    public DataTemplate FontTemplate { get; set; }
    public DataTemplate IconTemplate { get; set; }

    public override DataTemplate SelectTemplate(object item, DependencyObject container) {
        FormattingRule rule = item as FormattingRule;
        if(rule == null) return null;
        switch(rule.Type) {
            case FormattingType.Font:
                return FontTemplate;
            case FormattingType.Background:
                return BackgroundTemplate;
            case FormattingType.Icon:
                return IconTemplate;
        }
        return null;
    }
}

If you specify both the TableView.FormatConditionGeneratorTemplate and FormatConditionGeneratorTemplateSelector properties, the GridControl uses the template the template selector returns.

Refer to the following help topic for more information: How to: Bind the Grid to a Collection of Conditional Formatting Rules.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FormatConditionGeneratorTemplateSelector 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.

See Also