Export (0) Print
Expand All

DataGridAutoGeneratingColumnEventArgs.PropertyType Property

Gets the Type of the property bound to the generated column.

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

public Type PropertyType { get; private set; }

Property Value

Type: System.Type
The Type of the property bound to the generated column.

The following code example demonstrates how to use the PropertyType property. This example is part of a larger example available in the How to: Customize Auto-Generated Columns in the DataGrid Control topic.


private void dataGrid1_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
    // Modify the header of the Name column.
    if (e.Column.Header.ToString() == "Name")
        e.Column.Header = "Task";
    // Replace the DueDate column with a custom template column.
    if (e.PropertyName == "DueDate")
    {
        // Create a new template column.
        DataGridTemplateColumn templateColumn = new DataGridTemplateColumn();
        templateColumn.Header = "Due Date";
        templateColumn.CellTemplate = (DataTemplate)Resources["dueDateCellTemplate"];
        templateColumn.CellEditingTemplate = (DataTemplate)Resources["dueDateCellEditingTemplate"];
        templateColumn.SortMemberPath = "DueDate";
        // ...
        // Replace the auto-generated column with the templateColumn.
        e.Column = templateColumn;
    }

    // Cancel AutoGeneration of all boolean columns.
    if (e.PropertyType == typeof(bool))
        e.Cancel = true;
}


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.

Community Additions

ADD
Show:
© 2015 Microsoft