Freigeben über


DataGridBoundColumn.Binding Property

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

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

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

Syntax

'Declaration
Public Overridable Property Binding As Binding
public virtual Binding Binding { get; set; }
<sdk:dataGridBoundColumn Binding="bindingExpression"/>

XAML Values

Property Value

Type: System.Windows.Data.Binding
The binding to the column's display property in the data source. The default is nulla null reference (Nothing in Visual Basic).

Exceptions

Exception Condition
InvalidOperationException

When changing the value of this property, the current cell edit cannot be committed or reverted.

Remarks

Changing the value of this property automatically commits the current cell edit.

Examples

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

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.