Skip to main content

DataControlBase.BandGeneratorTemplateSelector Property

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

Namespace: DevExpress.Xpf.Grid

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

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public DataTemplateSelector BandGeneratorTemplateSelector { get; set; }

Property Value

Type Description
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.
<Window.Resources>
    <!-- ... -->
    <local:BandTemplateSelector x:Key="BandTemplateSelector" 
                                MultiColumnBandTemplate="{StaticResource MultiColumnBandTemplate}" 
                                SingleColumnBandTemplate="{StaticResource SingleColumnBandTemplate}"/>
</Window.Resources>
<dxg:GridControl ...
                 BandsSource="{Binding Bands}" 
                 BandGeneratorTemplateSelector="{StaticResource BandTemplateSelector}"/>
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;
    }
}

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