Printer Friendly Version      Send     
Click to Rate and Give Feedback
.NET Framework Class Library for Silverlight
DataGridTemplateColumn Class
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

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
Visual C++
public ref class DataGridTemplateColumn : public DataGridColumn
JScript
public class DataGridTemplateColumn extends DataGridColumn

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.

XAML
<data:DataGrid x:Name="dataGrid5" 
    Height="120" Width="450" Margin="0,5,0,10" >            
    <data:DataGrid.Columns>

        <data:DataGridTemplateColumn Header="Name">
            <data:DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <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 Padding="5,0,5,0"
                            Text="{Binding FirstName}"/>
                        <TextBox Text="{Binding LastName}"/>
                    </StackPanel>
                </DataTemplate>
            </data:DataGridTemplateColumn.CellEditingTemplate> 
        </data:DataGridTemplateColumn>              

        <data:DataGridTextColumn
            Header="Address" Width="300"
            DisplayMemberBinding="{Binding Address}" />

    </data:DataGrid.Columns>
</data:DataGrid>

System..::.Object
  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.
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker