.NET Framework Class Library for Silverlight
DataGridColumn..::.Header Property

Gets or sets the content of the column header.

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

Visual Basic (Declaration)
Public Property Header As Object
    Get
    Set
Visual Basic (Usage)
Dim instance As DataGridColumn
Dim value As Object

value = instance.Header

instance.Header = value
C#
public Object Header { get; set; }
XAML Property Element Usage
<object>
  <object.Header>
    headerObject
  </object.Header>
</object>
XAML Attribute Usage
<object Header="text"/>

XAML Values

object

See Remarks in DataGridColumn.

headerObject

An object element that serves as header content. Use discretion when using objects as header content; not all Silverlight objects are suitable for use within the limited presentation surface that appears for headers.

text

A text string that serves as header content.

Property Value

Type: System..::.Object
The column header content. The default is nullNothingnullptra null reference (Nothing in Visual Basic).
Examples

The following code example demonstrates how to set the Header property in XAML. This example is part of a larger example available in the DataGrid class overview.

XAML
<data:DataGrid x:Name="dataGrid4" 
    Height="160" Margin="0,5,0,10" 
    RowHeight="40" AutoGenerateColumns="False" >    
    <data:DataGrid.Columns>
        <data:DataGridTextColumn 
            Header="First Name" 
            Width="SizeToHeader"
            Binding="{Binding FirstName}" 
            FontSize="20" />
        <data:DataGridTextColumn 
            Header="Last Name" 
            Width="SizeToCells"
            Binding="{Binding LastName}" 
            FontSize="20" />
        <data:DataGridTextColumn 
            Header="Address"
            Width="150"
            Binding="{Binding Address}" >
            <data:DataGridTextColumn.ElementStyle>
                <Style TargetType="TextBlock">
                    <Setter Property="TextWrapping" Value="Wrap"/>
                </Style>
            </data:DataGridTextColumn.ElementStyle>
            <data:DataGridTextColumn.EditingElementStyle>
                <Style TargetType="TextBox">
                    <Setter Property="Foreground" Value="Blue"/>
                </Style>
            </data:DataGridTextColumn.EditingElementStyle>
        </data:DataGridTextColumn>
        <data:DataGridCheckBoxColumn 
            Header="New?" 
            Width="40"
            Binding="{Binding IsNew}" />
        <data:DataGridCheckBoxColumn 
            Header="Subscribed?" 
            Width="Auto"
            Binding="{Binding IsSubscribed}" 
            IsThreeState="True" />
    </data:DataGrid.Columns>
</data:DataGrid>

The following code example demonstrates how to set the Header property in code. This example is part of a larger example available in the How to: Customize Auto-Generated Columns in the DataGrid Control topic.

Visual Basic
' Create a new template column.
Dim templateColumn As New DataGridTemplateColumn
templateColumn.Header = "Due Date"
templateColumn.CellTemplate = Me.Resources("dueDateCellTemplate")
templateColumn.CellEditingTemplate = Me.Resources("dueDateCellEditingTemplate")
templateColumn.SortMemberPath = "DueDate"
C#
// Create a new template column.
DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
templateColumn.Header = "Due Date";
templateColumn.CellTemplate = (DataTemplate)Resources["dueDateCellTemplate"];
templateColumn.CellEditingTemplate = (DataTemplate)Resources["dueDateCellEditingTemplate"];
templateColumn.SortMemberPath = "DueDate";
Platforms

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

See Also

Reference

Other Resources

Tags :


Page view tracker