Click to Rate and Give Feedback

  Switch on low bandwidth view
This page is specific to
Microsoft Silverlight 3

Other versions are also available for the following:
.NET Framework Class Library for Silverlight
DataGridTemplateColumn Class

Represents a DataGrid column that hosts template-specified content in its cells.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)
Visual Basic (Declaration)
Public Class DataGridTemplateColumn _
    Inherits DataGridColumn
Visual Basic (Usage)
Dim instance As DataGridTemplateColumn
C#
public class DataGridTemplateColumn : DataGridColumn
XAML Object Element Usage
<data:DataGridTemplateColumn .../>

XAML Values

data:

A prefix that is defined to map the XML namespace for the System.Windows.Controls.Data assembly and the System.Windows.Controls CLR namespace.

The DataGridTemplateColumn type enables you to create your own column types by specifying the cell templates used to display values and enable editing. Set the CellTemplate property to specify the contents of cells that display values, but do not allow editing. Set the CellEditingTemplate property to specify the contents of cells in editing mode. If you set the column IsReadOnly property to true, the CellEditingTemplate property value is never used.

The following code example demonstrates how to specify and configure a DataGridTemplateColumn in XAML. This example is part of a larger example available in the DataGrid class overview.

<data:DataGrid x:Name="dataGrid5" 
    Height="125" Margin="0,5,0,10"
    AutoGenerateColumns="False"
    RowBackground="Azure"
    AlternatingRowBackground="LightSteelBlue">
    <data:DataGrid.Columns>
        <!-- Name Column -->
        <data:DataGridTemplateColumn Header="Name">
            <data:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                        <TextBlock Padding="5,0,5,0"
                            Text="{Binding FirstName}"/>
                        <TextBlock Text="{Binding LastName}"/>
                    </StackPanel>
                </DataTemplate>
            </data:DataGridTemplateColumn.CellTemplate> 
            <data:DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <TextBox Text="{Binding FirstName}" BorderThickness="0"/>
                        <TextBox Text="{Binding LastName}" BorderThickness="0"/>
                    </StackPanel>
                </DataTemplate>
            </data:DataGridTemplateColumn.CellEditingTemplate> 
        </data:DataGridTemplateColumn>              
        <!-- Address Column -->
        <data:DataGridTextColumn
            Header="Address" Width="300"
            Binding="{Binding Address}" />
    </data:DataGrid.Columns>
</data:DataGrid>

System..::.Object
  System.Windows..::.DependencyObject
    System.Windows.Controls..::.DataGridColumn
      System.Windows.Controls..::.DataGridTemplateColumn
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
data grid      anishah   |   Edit   |   Show History

send me

Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker