wpf-devexpress-dot-xpf-dot-grid-dot-tableview-fa909c7d.md
Gets or sets the format condition template selector. This is a dependency property.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public DataTemplateSelector FormatConditionGeneratorTemplateSelector { get; set; }
Public Property FormatConditionGeneratorTemplateSelector As DataTemplateSelector
| Type | Description |
|---|---|
| DataTemplateSelector |
A format condition template selector.
|
You can define conditional formatting rules in a ViewModel and apply them to the GridControl. To do this, follow the steps below:
Create a collection of conditional formatting rules in a ViewModel and specify a data template that generates format conditions.
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:
<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;
}
}
Public Class FormatConditionSelector
Inherits DataTemplateSelector
Public Property BackgroundTemplate As DataTemplate
Public Property FontTemplate As DataTemplate
Public Property IconTemplate As DataTemplate
Public Overrides Function SelectTemplate(ByVal item As Object, ByVal container As DependencyObject) As DataTemplate
Dim rule As FormattingRule = TryCast(item, FormattingRule)
If rule Is Nothing Then Return Nothing
Select Case rule.Type
Case FormattingType.Font
Return FontTemplate
Case FormattingType.Background
Return BackgroundTemplate
Case FormattingType.Icon
Return IconTemplate
End Select
Return Nothing
End Function
End Class
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.
See Also