Represents a DataGrid column that hosts textual content in its cells.
Namespace:
System.Windows.Controls
Assembly:
System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)
Visual Basic (Declaration)
<StyleTypedPropertyAttribute(Property := "EditingElementStyle", StyleTargetType := GetType(TextBox))> _
<StyleTypedPropertyAttribute(Property := "ElementStyle", StyleTargetType := GetType(TextBlock))> _
Public Class DataGridTextColumn _
Inherits DataGridBoundColumn
Dim instance As DataGridTextColumn
[StyleTypedPropertyAttribute(Property = "EditingElementStyle", StyleTargetType = typeof(TextBox))]
[StyleTypedPropertyAttribute(Property = "ElementStyle", StyleTargetType = typeof(TextBlock))]
public class DataGridTextColumn : DataGridBoundColumn
XAML Object Element Usage
<data:DataGridTextColumn .../>
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.
This column hosts TextBlock elements for cells that are not in editing mode and a TextBox control for a cell that is in editing mode.
By default, the DataGrid control generates columns automatically when you set the ItemsSource property. The generated columns are of type DataGridCheckBoxColumn for bound Boolean (and nullable Boolean) properties, and of type DataGridTextColumn for all other properties. If a property does not have a String or numeric value type, the generated text box columns are read-only and display the data object's ToString value.
The following code example demonstrates how to specify and configure a DataGridTextColumn in XAML. This example is part of a larger example available in the DataGrid class overview.
<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>
System..::.Object
System.Windows..::.DependencyObject
System.Windows.Controls..::.DataGridColumn
System.Windows.Controls..::.DataGridBoundColumn
System.Windows.Controls..::.DataGridTextColumn
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.
Reference