TreeListView.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

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 TreeListView.FormatConditionsSource property and the format condition template to the TreeListView.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:TreeListView 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 TreeListView.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.

See Also