DataGridBoundColumn.ElementStyle Property

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.

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

public Style ElementStyle { get; set; }
<sdk:dataGridBoundColumn>
  <sdk:dataGridBoundColumn.ElementStyle>
    inlineStyle
  </sdk:dataGridBoundColumn.ElementStyle>
</sdk:dataGridBoundColumn>
<sdk:dataGridBoundColumn ElementStyle="styleReference"/>

XAML Values

sdk:dataGridBoundColumn

Typically, either sdk:DataGridTextColumn or sdk:DataGridCheckBoxColumn.

inlineStyle

A single Style object element. The TargetType used for this Style depends on the Type of the element. This style can define setters for any properties of the element that can be styled. See Inline Styles and Templates.

styleReference

A StaticResource reference to a Style that defines the appearance of the column. This style should use the TargetType of the element.

Property Value

Type: System.Windows.Style
The style that is used when rendering a display-only element. The default is null.

The following code example demonstrates how to set the ElementStyle property 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>


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: