DataGrid.Columns Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets a collection that contains all the columns in the control.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)


Public ReadOnly Property Columns As ObservableCollection(Of DataGridColumn)
public ObservableCollection<DataGridColumn> Columns { get; }

XAML Values

Property Value

Type: System.Collections.ObjectModel.ObservableCollection<DataGridColumn>
The columns in the control.


Use the Columns collection to add columns, remove columns, or update properties on the columns.

Each column in the Columns collection defines a column in the DataGrid. Columns in the collection must derive from DataGridColumn. DataGridBoundColumn, which adds support for binding, derives from DataGridColumn and is the base for the defined column types.

The following table lists the two defined column types that the DataGrid provides.

Column type

Data type


Used to display text.


Used to display Boolean data.

In addition, you can define your own custom column by using DataGridTemplateColumn .

You can modify the Columns collection at run time regardless of whether it contains generated columns. However, if you specify columns in XAML, you should not set AutoGenerateColumns to true.

You cannot add a column to the Columns collection of more than one DataGrid. If you try to do this, an InvalidOperationException will be thrown.

If you try to modify the Columns collection while the DataGrid is in editing mode, the control will automatically commit the edit. If the control cannot commit the edit, it will throw an InvalidOperationException.


The following code example demonstrates how to populate the Columns collection in XAML. This example is part of a larger example available in the DataGrid class overview.

<sdk:DataGrid x:Name="dataGrid4" 
    Height="160" Margin="0,5,0,10" 
    RowHeight="40" AutoGenerateColumns="False" >    
            Header="First Name" 
            Binding="{Binding FirstName}" 
            FontSize="20" />
            Header="Last Name" 
            Binding="{Binding LastName}" 
            FontSize="20" />
            Binding="{Binding Address}" >
                <Style TargetType="TextBlock">
                    <Setter Property="TextWrapping" Value="Wrap"/>
                <Style TargetType="TextBox">
                    <Setter Property="Foreground" Value="Blue"/>
            Binding="{Binding IsNew}" />
            Binding="{Binding IsSubscribed}" 
            IsThreeState="True" />

Version Information


Supported in: 5, 4, 3


For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.