Back to Devexpress

DataControlBase.BandGeneratorTemplateSelector Property

wpf-devexpress-dot-xpf-dot-grid-dot-datacontrolbase-9f5022a1.md

latest4.4 KB
Original Source

DataControlBase.BandGeneratorTemplateSelector Property

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

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public DataTemplateSelector BandGeneratorTemplateSelector { get; set; }
vb
Public Property BandGeneratorTemplateSelector As DataTemplateSelector

Property Value

TypeDescription
DataTemplateSelector

A band template selector.

|

Remarks

You can define bands in a ViewModel and display them in the GridControl. To do this, follow the steps below:

  1. Create a collection of grid bands in a ViewModel and specify a data template that generates bands.

  2. Assign the band collection to the BandsSource property and the band template to the DataControlBase.BandGeneratorTemplate property.

If you have multiple band 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 BandGeneratorTemplateSelector property.
xaml
<Window.Resources>
    <!-- ... -->
    <local:BandTemplateSelector x:Key="BandTemplateSelector" 
                                MultiColumnBandTemplate="{StaticResource MultiColumnBandTemplate}" 
                                SingleColumnBandTemplate="{StaticResource SingleColumnBandTemplate}"/>
</Window.Resources>
<dxg:GridControl ...
                 BandsSource="{Binding Bands}" 
                 BandGeneratorTemplateSelector="{StaticResource BandTemplateSelector}"/>
csharp
public class BandTemplateSelector : DataTemplateSelector {

    public DataTemplate SingleColumnBandTemplate { get; set; }
    public DataTemplate MultiColumnBandTemplate { get; set; }

    public override DataTemplate SelectTemplate(object item, DependencyObject container) {
        Band band = item as Band;
        if(band == null) return null;
        if(band.Header == "Position") {
            return SingleColumnBandTemplate;
        }
        return MultiColumnBandTemplate;
    }
}
vb
Public Class BandTemplateSelector
    Inherits DataTemplateSelector

    Public Property SingleColumnBandTemplate As DataTemplate
    Public Property MultiColumnBandTemplate As DataTemplate

    Public Overrides Function SelectTemplate(ByVal item As Object, ByVal container As DependencyObject) As DataTemplate
        Dim band As Band = TryCast(item, Band)
        If band Is Nothing Then Return Nothing

        If band.Header = "Position" Then
            Return SingleColumnBandTemplate
        End If

        Return MultiColumnBandTemplate
    End Function
End Class

If you specify both the DataControlBase.BandGeneratorTemplate and BandGeneratorTemplateSelector , the GridControl uses the template the template selector returns.

Refer to the following help topic for more information: How to: Bind the Grid to Bands Specified in ViewModel.

See Also

DataControlBase Class

DataControlBase Members

DevExpress.Xpf.Grid Namespace