Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DataControlBase.ColumnGeneratorTemplate Property

Gets or sets a template that describes grid columns. 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 DataTemplate ColumnGeneratorTemplate { get; set; }

#Property Value

Type Description
DataTemplate

The column template.

#Remarks

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

  1. Create a collection of grid columns in a ViewModel.
  2. Specify a data template that generates columns:

    <Window.Resources>
        <DataTemplate x:Key="DefaultColumnTemplate">
            <dxg:GridColumn FieldName="{Binding Path=(dxci:DependencyObjectExtensions.DataContext).FieldName, RelativeSource={RelativeSource Self}}"/>
        </DataTemplate>
    </Window.Resources>
    
  3. Assign the column collection to the ColumnsSource property and the column template to the ColumnGeneratorTemplate property:

    <dxg:GridControl ...
                     ColumnsSource="{Binding Columns}" 
                     ColumnGeneratorTemplate="{StaticResource DefaultColumnTemplate}"/>
    

If you have multiple column templates, use the ColumnGeneratorTemplateSelector property to specify a template selector that chooses a template based on a column type.

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

See Also