Export (0) Print
Expand All
1 out of 12 rated this helpful - Rate this topic

DataGridTemplateColumn Class

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

System.Object
  System.Windows.DependencyObject
    System.Windows.Controls.DataGridColumn
      System.Windows.Controls.DataGridTemplateColumn

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)
public class DataGridTemplateColumn : DataGridColumn
<sdk:DataGridTemplateColumn .../>

The DataGridTemplateColumn type exposes the following members.

  NameDescription
Public methodDataGridTemplateColumnInitializes a new instance of the DataGridTemplateColumn class.
Top
  NameDescription
Public propertyActualWidthGets the current width of the column in pixels. (Inherited from DataGridColumn.)
Public propertyCanUserReorderGets or sets a value that indicates whether the user can change the column display position by dragging the column header. (Inherited from DataGridColumn.)
Public propertyCanUserResizeGets or sets a value that indicates whether the user can adjust the column width using the mouse. (Inherited from DataGridColumn.)
Public propertyCanUserSortGets or sets a value that indicates whether the user can sort the column by clicking the column header. (Inherited from DataGridColumn.)
Public propertyCellEditingTemplateGets or sets the template that is used to display the contents of a cell that is in editing mode.
Public propertyCellStyleGets or sets the style that is used when rendering cells in the column. (Inherited from DataGridColumn.)
Public propertyCellTemplateGets or sets the template that is used to display the contents of a cell that is not in editing mode.
Public propertyClipboardContentBindingGets or sets the binding that provides access to cell contents for clipboard operations. (Inherited from DataGridColumn.)
Public propertyDispatcherGets the Dispatcher this object is associated with. (Inherited from DependencyObject.)
Public propertyDisplayIndexGets or sets the display position of the column relative to the other columns in the DataGrid. (Inherited from DataGridColumn.)
Public propertyDragIndicatorStyleGets or sets the style that is used to render the column while it is being dragged. (Inherited from DataGridColumn.)
Public propertyHeaderGets or sets the content of the column header. (Inherited from DataGridColumn.)
Public propertyHeaderStyleGets or sets the style that is used when rendering the column header. (Inherited from DataGridColumn.)
Public propertyIsAutoGeneratedGets a value that indicates whether the column is auto-generated. (Inherited from DataGridColumn.)
Public propertyIsFrozenGets a value that indicates whether the column is prevented from scrolling horizontally. (Inherited from DataGridColumn.)
Public propertyIsReadOnlyGets or sets a value that indicates whether cells in the column can be edited. (Inherited from DataGridColumn.)
Public propertyMaxWidthGets or sets the maximum column width in pixels. (Inherited from DataGridColumn.)
Public propertyMinWidthGets or sets the minimum column width in pixels. (Inherited from DataGridColumn.)
Public propertySortMemberPathGets or sets a property name, or a period-delimited hierarchy of property names, that indicates the member to sort by. (Inherited from DataGridColumn.)
Public propertyVisibilityGets or sets the visibility of the column. (Inherited from DataGridColumn.)
Public propertyWidthGets or sets the column width or an automatic sizing mode. (Inherited from DataGridColumn.)
Top
  NameDescription
Protected methodCancelCellEditEnds the edit on a data grid cell and reverts any changes. (Overrides DataGridColumn.CancelCellEdit(FrameworkElement, Object).)
Public methodCheckAccessDetermines whether the calling thread has access to this object. (Inherited from DependencyObject.)
Public methodClearValueClears the local value of a dependency property. (Inherited from DependencyObject.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Protected methodGenerateEditingElementGets an element defined by the CellEditingTemplate that is bound to the column's Binding property value. (Overrides DataGridColumn.GenerateEditingElement(DataGridCell, Object).)
Protected methodGenerateElementGets an element defined by the CellTemplate that is bound to the column's Binding property value. (Overrides DataGridColumn.GenerateElement(DataGridCell, Object).)
Public methodGetAnimationBaseValueReturns any base value established for a Silverlight dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject.)
Public methodGetCellContent(DataGridRow)Gets the Content property value for the cell at the intersection of this column and the specified row. (Inherited from DataGridColumn.)
Public methodGetCellContent(Object)Gets the Content property value for the cell at the intersection of this column and the row that represents the specified data item. (Inherited from DataGridColumn.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetValueReturns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodNotifyPropertyChangedCalled by a specific column type when one of its properties changes and its current cells need to be updated. (Inherited from DataGridColumn.)
Protected methodPrepareCellForEditCalled when a cell in the column enters editing mode. (Overrides DataGridColumn.PrepareCellForEdit(FrameworkElement, RoutedEventArgs).)
Public methodReadLocalValueReturns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject.)
Protected methodRefreshCellContentRefreshes the contents of a cell in the column in response to a column property value change. (Inherited from DataGridColumn.)
Public methodSetValueSets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.


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


Silverlight

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.