DataGridTemplateColumn Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a DataGrid column that hosts template-specified content in its cells.
public ref class DataGridTemplateColumn : System::Windows::Controls::DataGridColumn
public class DataGridTemplateColumn : System.Windows.Controls.DataGridColumn
type DataGridTemplateColumn = class
inherit DataGridColumn
Public Class DataGridTemplateColumn
Inherits DataGridColumn
- Inheritance
The following example shows how to create a DataGridTemplateColumn.
<Grid>
<Grid.Resources>
<!--DataTemplate for Published Date column defined in Grid.Resources. PublishDate is a property on the ItemsSource of type DateTime -->
<DataTemplate x:Key="DateTemplate" >
<StackPanel Width="20" Height="30">
<Border Background="LightBlue" BorderBrush="Black" BorderThickness="1">
<TextBlock Text="{Binding PublishDate, StringFormat={}{0:MMM}}" FontSize="8" HorizontalAlignment="Center" />
</Border>
<Border Background="White" BorderBrush="Black" BorderThickness="1">
<TextBlock Text="{Binding PublishDate, StringFormat={}{0:yyyy}}" FontSize="8" FontWeight="Bold" HorizontalAlignment="Center" />
</Border>
</StackPanel>
</DataTemplate>
<!--DataTemplate for the Published Date column when in edit mode. -->
<DataTemplate x:Key="EditingDateTemplate">
<DatePicker SelectedDate="{Binding PublishDate}" />
</DataTemplate>
</Grid.Resources>
<DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<!--Custom column that shows the published date-->
<DataGridTemplateColumn Header="Publish Date" CellTemplate="{StaticResource DateTemplate}" CellEditingTemplate="{StaticResource EditingDateTemplate}" />
</DataGrid.Columns>
</DataGrid>
</Grid>
The following illustration shows the output from the previous XAML.
The DataGridTemplateColumn type enables you to create your own column types by specifying the cell templates to use when displaying and editing values. To specify the template that is used to display the contents of a cell that is not in editing mode, set the CellTemplate property. To specify the template that is used to display the contents of a cell that is in editing mode, set the CellEditingTemplate property. For more information about templates, see Data Templating Overview and Styling and Templating.
For convenience, DataGrid provides the following pre-defined column types:
Column Type | Data Display |
---|---|
DataGridHyperlinkColumn | Use to display URI data. |
DataGridComboBoxColumn | Use to display enumeration data. |
DataGridTextColumn | Use to display text. |
DataGridCheckBoxColumn | Use to display Boolean data. |
Data |
Initializes a new instance of the DataGridTemplateColumn class. |
Cell |
Identifies the CellEditingTemplate dependency property. |
Cell |
Identifies the CellEditingTemplateSelector dependency property. |
Cell |
Identifies the CellTemplate dependency property. |
Cell |
Identifies the CellEditingTemplateSelector dependency property. |
Actual |
Gets the current width of the column, in device-independent units (1/96th inch per unit). (Inherited from DataGridColumn) |
Can |
Gets or sets a value that indicates whether the user can change the column display position by dragging the column header. (Inherited from DataGridColumn) |
Can |
Gets or sets a value that indicates whether the user can adjust the column width by using the mouse. (Inherited from DataGridColumn) |
Can |
Gets or sets a value that indicates whether the user can sort the column by clicking the column header. (Inherited from DataGridColumn) |
Cell |
Gets or sets the template to use to display the contents of a cell that is in editing mode. |
Cell |
Gets or sets the object that determines which template to use to display the contents of a cell that is in editing mode. |
Cell |
Gets or sets the style that is used to render cells in the column. (Inherited from DataGridColumn) |
Cell |
Gets or sets the template to use to display the contents of a cell that is not in editing mode. |
Cell |
Gets or sets the object that determines which template to use to display the contents of a cell that is not in editing mode. |
Clipboard |
Gets or sets the binding object to use when getting or setting cell content for the clipboard. (Inherited from DataGridColumn) |
Data |
Gets the DataGrid control that contains this column. (Inherited from DataGridColumn) |
Dependency |
Gets the DependencyObjectType that wraps the CLR type of this instance. (Inherited from DependencyObject) |
Dispatcher |
Gets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject) |
Display |
Gets or sets the display position of the column relative to the other columns in the DataGrid. (Inherited from DataGridColumn) |
Drag |
Gets or sets the style object to apply to the column header during a drag operation. (Inherited from DataGridColumn) |
Header |
Gets or sets the content of the column header. (Inherited from DataGridColumn) |
Header |
Gets or sets the format pattern to apply to the content of the column header. (Inherited from DataGridColumn) |
Header |
Gets or sets the style that is used when rendering the column header. (Inherited from DataGridColumn) |
Header |
Gets or sets the template that defines the visual representation of the column header. (Inherited from DataGridColumn) |
Header |
Gets or sets the object that selects which template to use for the column header. (Inherited from DataGridColumn) |
Is |
Gets a value that indicates whether the column is auto-generated. (Inherited from DataGridColumn) |
Is |
Gets a value that indicates whether the column is prevented from scrolling horizontally. (Inherited from DataGridColumn) |
Is |
Gets or sets a value that indicates whether cells in the column can be edited. (Inherited from DataGridColumn) |
Is |
Gets a value that indicates whether this instance is currently sealed (read-only). (Inherited from DependencyObject) |
Max |
Gets or sets the maximum width constraint of the column. (Inherited from DataGridColumn) |
Min |
Gets or sets the minimum width constraint of the column. (Inherited from DataGridColumn) |
Sort |
Gets or sets the sort direction (ascending or descending) of the column. (Inherited from DataGridColumn) |
Sort |
Gets or sets a property name, or a period-delimited hierarchy of property names, that indicates the member to sort by. (Inherited from DataGridColumn) |
Visibility |
Gets or sets the visibility of the column. (Inherited from DataGridColumn) |
Width |
Gets or sets the column width or automatic sizing mode. (Inherited from DataGridColumn) |
Cancel |
Causes the cell being edited to revert to the original, unedited value. (Inherited from DataGridColumn) |
Check |
Determines whether the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject) |
Clear |
Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier. (Inherited from DependencyObject) |
Clear |
Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey. (Inherited from DependencyObject) |
Coerce |
Coerces the value of the specified dependency property. This is accomplished by invoking any CoerceValueCallback function specified in property metadata for the dependency property as it exists on the calling DependencyObject. (Inherited from DependencyObject) |
Commit |
Performs any required validation before exiting cell editing mode. (Inherited from DataGridColumn) |
Equals(Object) |
Determines whether a provided DependencyObject is equivalent to the current DependencyObject. (Inherited from DependencyObject) |
Generate |
Gets an element defined by the CellEditingTemplate that is bound to the column's Binding property value. |
Generate |
Gets an element defined by the CellTemplate that is bound to the column's Binding property value. |
Get |
Retrieves the Content property value for the cell at the intersection of this column and the specified row. (Inherited from DataGridColumn) |
Get |
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) |
Get |
Gets a hash code for this DependencyObject. (Inherited from DependencyObject) |
Get |
Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject. (Inherited from DependencyObject) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Get |
Returns the current effective value of a dependency property on this instance of a DependencyObject. (Inherited from DependencyObject) |
Invalidate |
Re-evaluates the effective value for the specified dependency property. (Inherited from DependencyObject) |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
Notify |
Notifies the DataGrid that contains this column that a column property has changed. (Inherited from DataGridColumn) |
On |
Determines the value of the IsReadOnly property based on the property rules of the DataGrid that contains this column. (Inherited from DataGridColumn) |
On |
Raises the CopyingCellClipboardContent event. (Inherited from DataGridColumn) |
On |
Raises the PastingCellClipboardContent event. (Inherited from DataGridColumn) |
On |
Invoked whenever the effective value of any dependency property on this DependencyObject has been updated. The specific dependency property that changed is reported in the event data. (Inherited from DependencyObject) |
Prepare |
When overridden in a derived class, sets cell content as needed for editing. (Inherited from DataGridColumn) |
Read |
Returns the local value of a dependency property, if it exists. (Inherited from DependencyObject) |
Refresh |
Refreshes the contents of a cell in the column in response to a template property value change. |
Set |
Sets the value of a dependency property without changing its value source. (Inherited from DependencyObject) |
Set |
Sets the local value of a dependency property, specified by its dependency property identifier. (Inherited from DependencyObject) |
Set |
Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property. (Inherited from DependencyObject) |
Should |
Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property. (Inherited from DependencyObject) |
To |
Returns a string that represents the current object. (Inherited from Object) |
Verify |
Enforces that the calling thread has access to this DispatcherObject. (Inherited from DispatcherObject) |
Copying |
Occurs after the cell clipboard content is prepared. (Inherited from DataGridColumn) |
Pasting |
Occurs before the clipboard content is moved to the cell. (Inherited from DataGridColumn) |
Product | Versions |
---|---|
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: