pmf
pmf

Reputation: 7759

WPF: Bind to property of a parent element

I'm using a DataGrid and would like to introduce a style trigger for cells that sets the background color of the cell depending on the column's IsReadOnly property. I think there is some way to get from the cell level to the column level using RelativeSource (navigating all the way up to grid and from there back down to the column), but I cannot figure out the exact path to use.

Upvotes: 0

Views: 662

Answers (1)

Guerudo
Guerudo

Reputation: 361

Put the following code inside your DataGrid :

<DataGrid.CellStyle>
    <Style TargetType="DataGridCell">
        <Style.Triggers>
             <DataTrigger Binding="{Binding Path=IsReadOnly, RelativeSource={RelativeSource Self} }"
                          Value="True">
                 <Setter Property="Background" Value="Red"/>
             </DataTrigger>
        </Style.Triggers>
    </Style>
</DataGrid.CellStyle>

Upvotes: 2

Related Questions