DataGridTextColumn Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Represents a DataGrid column that hosts textual content in its cells.

Inheritance Hierarchy

System.Object
  System.Windows.DependencyObject
    System.Windows.Controls.DataGridColumn
      System.Windows.Controls.DataGridBoundColumn
        System.Windows.Controls.DataGridTextColumn

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls.Data (in System.Windows.Controls.Data.dll)

Syntax

'Declaration
<StyleTypedPropertyAttribute(Property := "EditingElementStyle", StyleTargetType := GetType(TextBox))> _
<StyleTypedPropertyAttribute(Property := "ElementStyle", StyleTargetType := GetType(TextBlock))> _
Public Class DataGridTextColumn _
    Inherits DataGridBoundColumn
[StyleTypedPropertyAttribute(Property = "EditingElementStyle", StyleTargetType = typeof(TextBox))]
[StyleTypedPropertyAttribute(Property = "ElementStyle", StyleTargetType = typeof(TextBlock))]
public class DataGridTextColumn : DataGridBoundColumn
<sdk:DataGridTextColumn .../>

The DataGridTextColumn type exposes the following members.

Constructors

  Name Description
Public method DataGridTextColumn Initializes a new instance of the DataGridTextColumn class.

Top

Properties

  Name Description
Public property ActualWidth Gets the current width of the column in pixels. (Inherited from DataGridColumn.)
Public property Binding Gets or sets the binding that associates the column with a property in the data source. (Inherited from DataGridBoundColumn.)
Public property CanUserReorder Gets or sets a value that indicates whether the user can change the column display position by dragging the column header. (Inherited from DataGridColumn.)
Public property CanUserResize Gets or sets a value that indicates whether the user can adjust the column width using the mouse. (Inherited from DataGridColumn.)
Public property CanUserSort Gets or sets a value that indicates whether the user can sort the column by clicking the column header. (Inherited from DataGridColumn.)
Public property CellStyle Gets or sets the style that is used when rendering cells in the column. (Inherited from DataGridColumn.)
Public property ClipboardContentBinding Gets or sets the binding that provides access to cell contents for clipboard operations. (Inherited from DataGridBoundColumn.)
Public property Dispatcher Gets the Dispatcher this object is associated with. (Inherited from DependencyObject.)
Public property DisplayIndex Gets or sets the display position of the column relative to the other columns in the DataGrid. (Inherited from DataGridColumn.)
Public property DragIndicatorStyle Gets or sets the style that is used to render the column while it is being dragged. (Inherited from DataGridColumn.)
Public property EditingElementStyle Gets or sets the style that is used when rendering the element that the column displays for a cell in editing mode. (Inherited from DataGridBoundColumn.)
Public property ElementStyle Gets or sets the style that is used when rendering the element that the column displays for a cell that is not in editing mode. (Inherited from DataGridBoundColumn.)
Public property FontFamily Gets or sets the font family of the content of cells in the column.
Public property FontSize Gets or sets the font size of the content of cells in the column.
Public property FontStyle Gets or sets the font style of the content of cells in the column.
Public property FontWeight Gets or sets the font weight of the contents of cells in the column.
Public property Foreground Gets or sets the brush that is used to paint the text contents of cells in the column.
Public property Header Gets or sets the content of the column header. (Inherited from DataGridColumn.)
Public property HeaderStyle Gets or sets the style that is used when rendering the column header. (Inherited from DataGridColumn.)
Public property IsAutoGenerated Gets a value that indicates whether the column is auto-generated. (Inherited from DataGridColumn.)
Public property IsFrozen Gets a value that indicates whether the column is prevented from scrolling horizontally. (Inherited from DataGridColumn.)
Public property IsReadOnly Gets or sets a value that indicates whether cells in the column can be edited. (Inherited from DataGridColumn.)
Public property MaxWidth Gets or sets the maximum column width in pixels. (Inherited from DataGridColumn.)
Public property MinWidth Gets or sets the minimum column width in pixels. (Inherited from DataGridColumn.)
Public property SortMemberPath Gets or sets a property name, or a period-delimited hierarchy of property names, that indicates the member to sort by. (Inherited from DataGridColumn.)
Public property Visibility Gets or sets the visibility of the column. (Inherited from DataGridColumn.)
Public property Width Gets or sets the column width or an automatic sizing mode. (Inherited from DataGridColumn.)

Top

Methods

  Name Description
Protected method CancelCellEdit Causes the column cell being edited to revert to the specified value. (Overrides DataGridColumn.CancelCellEdit(FrameworkElement, Object).)
Public method CheckAccess Determines whether the calling thread has access to this object. (Inherited from DependencyObject.)
Public method ClearValue Clears the local value of a dependency property. (Inherited from DependencyObject.)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Protected method GenerateEditingElement Gets a TextBox control that is bound to the column's Binding property value. (Overrides DataGridColumn.GenerateEditingElement(DataGridCell, Object).)
Protected method GenerateElement Gets a read-only TextBlock element that is bound to the column's Binding property value. (Overrides DataGridColumn.GenerateElement(DataGridCell, Object).)
Public method GetAnimationBaseValue Returns any base value established for a Silverlight dependency property, which would apply in cases where an animation is not active. (Inherited from DependencyObject.)
Public method GetCellContent(DataGridRow) Gets the Content property value for the cell at the intersection of this column and the specified row. (Inherited from DataGridColumn.)
Public method GetCellContent(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 method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method GetValue Returns the current effective value of a dependency property from a DependencyObject. (Inherited from DependencyObject.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method NotifyPropertyChanged Called by a specific column type when one of its properties changes and its current cells need to be updated. (Inherited from DataGridColumn.)
Protected method PrepareCellForEdit Called when a cell in the column enters editing mode. (Overrides DataGridColumn.PrepareCellForEdit(FrameworkElement, RoutedEventArgs).)
Public method ReadLocalValue Returns the local value of a dependency property, if a local value is set. (Inherited from DependencyObject.)
Protected method RefreshCellContent Refreshes the contents of a cell in the column in response to a column property value change. (Overrides DataGridColumn.RefreshCellContent(FrameworkElement, String).)
Public method SetValue Sets the local value of a dependency property on a DependencyObject. (Inherited from DependencyObject.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Fields

  Name Description
Public fieldStatic member FontFamilyProperty Identifies the FontFamily dependency property.

Top

Remarks

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.

Examples

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.

<sdk:DataGrid x:Name="dataGrid4" 
    Height="160" Margin="0,5,0,10" 
    RowHeight="40" AutoGenerateColumns="False" >    
    <sdk:DataGrid.Columns>
        <sdk:DataGridTextColumn 
            Header="First Name" 
            Width="SizeToHeader"
            Binding="{Binding FirstName}" 
            FontSize="20" />
        <sdk:DataGridTextColumn 
            Header="Last Name" 
            Width="SizeToCells"
            Binding="{Binding LastName}" 
            FontSize="20" />
        <sdk:DataGridTextColumn 
            Header="Address"
            Width="150"
            Binding="{Binding Address}" >
            <sdk:DataGridTextColumn.ElementStyle>
                <Style TargetType="TextBlock">
                    <Setter Property="TextWrapping" Value="Wrap"/>
                </Style>
            </sdk:DataGridTextColumn.ElementStyle>
            <sdk:DataGridTextColumn.EditingElementStyle>
                <Style TargetType="TextBox">
                    <Setter Property="Foreground" Value="Blue"/>
                </Style>
            </sdk:DataGridTextColumn.EditingElementStyle>
        </sdk:DataGridTextColumn>
        <sdk:DataGridCheckBoxColumn 
            Header="New?" 
            Width="40"
            Binding="{Binding IsNew}" />
        <sdk:DataGridCheckBoxColumn 
            Header="Subscribed?" 
            Width="Auto"
            Binding="{Binding IsSubscribed}" 
            IsThreeState="True" />
    </sdk:DataGrid.Columns>
</sdk:DataGrid>

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

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

Thread Safety

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