Επεξεργασία

Κοινή χρήση μέσω


DataGridTextColumn Class

Definition

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

public ref class DataGridTextColumn : System::Windows::Controls::DataGridBoundColumn
public class DataGridTextColumn : System.Windows.Controls.DataGridBoundColumn
type DataGridTextColumn = class
    inherit DataGridBoundColumn
Public Class DataGridTextColumn
Inherits DataGridBoundColumn
Inheritance

Examples

The following example creates a DataGrid that has customized text columns and uses XML data as the source. The illustration earlier in this topic shows how this code is displayed. For more information about binding to XML data, see How to: Bind to XML Data Using an XMLDataProvider and XPath Queries.

<Window.Resources>
    <XmlDataProvider x:Key="customerdata" Source="customers.xml" XPath="Data" />
</Window.Resources>
<Grid>
    <DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Source={StaticResource customerdata}, XPath=Customer}">
        <DataGrid.Columns>
            <DataGridTextColumn Header="First Name" Binding="{Binding XPath=@FirstName}" FontFamily="Arial" FontStyle="Italic" />
            <DataGridTextColumn Header="Last Name" Binding="{Binding XPath=@LastName}" FontFamily="Arial" FontWeight="Bold" />
        </DataGrid.Columns>
    </DataGrid>
</Grid>

Remarks

Use DataGridTextColumn to display columns of data as text. The following illustration shows an example of two DataGridTextColumn types.

Two DataGridTextColumns

To create a column, add it to the Columns collection. To populate the column, bind the column to the data by using the Binding property. The Binding property is applied to the TextBlock or TextBox element created in the column. The DataContext for the element in each cell is the data item for the row the cell is in. Therefore, to set up the binding you only have to set the Binding.Path. Optionally, you can specify a Binding.Converter if you want to convert the data or the StringFormat. For more information about data binding, see Data Binding (WPF).

Note DataGridTextColumn creates a TextBlock element in the non-editing mode and a TextBox element in the editing mode.

You can customize the DataGridTextColumn by setting properties, such as Width, Header, FontSize, and IsReadOnly.

If you want to display other types of data, DataGrid provides the following column types:

Column Type Data Display
DataGridHyperlinkColumn Use to display URI data.
DataGridComboBoxColumn Use to display enumeration data.
DataGridCheckBoxColumn Use to display Boolean data.

If you want to use other controls in your DataGrid, you can create your own column types by using DataGridTemplateColumn.

Constructors

DataGridTextColumn()

Initializes a new instance of the DataGridTextColumn class.

Fields

FontFamilyProperty

Identifies the FontFamily dependency property.

FontSizeProperty

Identifies the FontSize dependency property.

FontStyleProperty

Identifies the FontStyle dependency property.

FontWeightProperty

Identifies the FontWeight dependency property.

ForegroundProperty

Identifies the Foreground dependency property.

Properties

ActualWidth

Gets the current width of the column, in device-independent units (1/96th inch per unit).

(Inherited from DataGridColumn)
Binding

Gets or sets the binding that associates the column with a property in the data source.

(Inherited from DataGridBoundColumn)
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)
CanUserResize

Gets or sets a value that indicates whether the user can adjust the column width by using the mouse.

(Inherited from DataGridColumn)
CanUserSort

Gets or sets a value that indicates whether the user can sort the column by clicking the column header.

(Inherited from DataGridColumn)
CellStyle

Gets or sets the style that is used to render cells in the column.

(Inherited from DataGridColumn)
ClipboardContentBinding

Gets or sets the binding object to use when getting or setting cell content for the clipboard.

(Inherited from DataGridBoundColumn)
DataGridOwner

Gets the DataGrid control that contains this column.

(Inherited from DataGridColumn)
DefaultEditingElementStyle

The default value of the EditingElementStyle property.

DefaultElementStyle

The default value of the ElementStyle property.

DependencyObjectType

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)
DisplayIndex

Gets or sets the display position of the column relative to the other columns in the DataGrid.

(Inherited from DataGridColumn)
DragIndicatorStyle

Gets or sets the style object to apply to the column header during a drag operation.

(Inherited from DataGridColumn)
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)
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)
FontFamily

Gets or sets the font family for the content of cells in the column.

FontSize

Gets or sets the font size for the content of cells in the column.

FontStyle

Gets or sets the font style for the content of cells in the column.

FontWeight

Gets or sets the font weight for the content of cells in the column.

Foreground

Gets or sets the Brush that is used to paint the text contents of cells in the column.

Header

Gets or sets the content of the column header.

(Inherited from DataGridColumn)
HeaderStringFormat

Gets or sets the format pattern to apply to the content of the column header.

(Inherited from DataGridColumn)
HeaderStyle

Gets or sets the style that is used when rendering the column header.

(Inherited from DataGridColumn)
HeaderTemplate

Gets or sets the template that defines the visual representation of the column header.

(Inherited from DataGridColumn)
HeaderTemplateSelector

Gets or sets the object that selects which template to use for the column header.

(Inherited from DataGridColumn)
IsAutoGenerated

Gets a value that indicates whether the column is auto-generated.

(Inherited from DataGridColumn)
IsFrozen

Gets a value that indicates whether the column is prevented from scrolling horizontally.

(Inherited from DataGridColumn)
IsReadOnly

Gets or sets a value that indicates whether cells in the column can be edited.

(Inherited from DataGridColumn)
IsSealed

Gets a value that indicates whether this instance is currently sealed (read-only).

(Inherited from DependencyObject)
MaxWidth

Gets or sets the maximum width constraint of the column.

(Inherited from DataGridColumn)
MinWidth

Gets or sets the minimum width constraint of the column.

(Inherited from DataGridColumn)
SortDirection

Gets or sets the sort direction (ascending or descending) of the column.

(Inherited from DataGridColumn)
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)
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)

Methods

CancelCellEdit(FrameworkElement, Object)

Causes the column cell being edited to revert to the specified value.

CancelCellEdit(FrameworkElement, Object)

Causes the cell being edited to revert to the original, unedited value.

(Inherited from DataGridColumn)
CheckAccess()

Determines whether the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)
ClearValue(DependencyProperty)

Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier.

(Inherited from DependencyObject)
ClearValue(DependencyPropertyKey)

Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey.

(Inherited from DependencyObject)
CoerceValue(DependencyProperty)

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)
CommitCellEdit(FrameworkElement)

Performs any required validation before exiting the edit mode.

CommitCellEdit(FrameworkElement)

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)
GenerateEditingElement(DataGridCell, Object)

Gets a TextBox control that is bound to the column's Binding property value.

GenerateElement(DataGridCell, Object)

Gets a read-only TextBlock control that is bound to the column's Binding property value.

GetCellContent(DataGridRow)

Retrieves the Content property value for the cell at the intersection of this column and the specified row.

(Inherited from DataGridColumn)
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)
GetHashCode()

Gets a hash code for this DependencyObject.

(Inherited from DependencyObject)
GetLocalValueEnumerator()

Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

(Inherited from DependencyObject)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetValue(DependencyProperty)

Returns the current effective value of a dependency property on this instance of a DependencyObject.

(Inherited from DependencyObject)
InvalidateProperty(DependencyProperty)

Re-evaluates the effective value for the specified dependency property.

(Inherited from DependencyObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
NotifyPropertyChanged(String)

Notifies the DataGrid that contains this column that a column property has changed.

(Inherited from DataGridColumn)
OnBindingChanged(BindingBase, BindingBase)

Notifies the DataGrid when the value of the Binding property changes.

(Inherited from DataGridBoundColumn)
OnCoerceIsReadOnly(Boolean)

Determines the value of the IsReadOnly property based on property rules from the data grid that contains this column.

(Inherited from DataGridBoundColumn)
OnCopyingCellClipboardContent(Object)

Raises the CopyingCellClipboardContent event.

(Inherited from DataGridColumn)
OnPastingCellClipboardContent(Object, Object)

Raises the PastingCellClipboardContent event.

(Inherited from DataGridColumn)
OnPropertyChanged(DependencyPropertyChangedEventArgs)

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)
PrepareCellForEdit(FrameworkElement, RoutedEventArgs)

Called when a cell in the column enters editing mode.

ReadLocalValue(DependencyProperty)

Returns the local value of a dependency property, if it exists.

(Inherited from DependencyObject)
RefreshCellContent(FrameworkElement, String)

Refreshes the contents of a cell in the column in response to a column property value change.

SetCurrentValue(DependencyProperty, Object)

Sets the value of a dependency property without changing its value source.

(Inherited from DependencyObject)
SetValue(DependencyProperty, Object)

Sets the local value of a dependency property, specified by its dependency property identifier.

(Inherited from DependencyObject)
SetValue(DependencyPropertyKey, Object)

Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

(Inherited from DependencyObject)
ShouldSerializeProperty(DependencyProperty)

Returns a value that indicates whether serialization processes should serialize the value for the provided dependency property.

(Inherited from DependencyObject)
ToString()

Returns a string that represents the current object.

(Inherited from Object)
VerifyAccess()

Enforces that the calling thread has access to this DispatcherObject.

(Inherited from DispatcherObject)

Events

CopyingCellClipboardContent

Occurs after the cell clipboard content is prepared.

(Inherited from DataGridColumn)
PastingCellClipboardContent

Occurs before the clipboard content is moved to the cell.

(Inherited from DataGridColumn)

Applies to