WPF DataGrid disable a row but allow one cell

856 views Asked by At

I have a DataGrid in WPF. The most left cell in every row is a CheckBox, which sets an Enabled property on the row's model (through a RowViewModel).

When the CheckBoxis unchecked on a certain row that row in the DataGrid should be disabled so all controls in the other columns of the row should be disabled, but not the CheckBox cell.

How can I easiest achieve that, still allowing the CheckBox cell to be enabled so the user can click the CheckBox in the most left cell in the row (so the user could still enable the object again hence making the complete row enabled as well)

1

There are 1 answers

1
mm8 On BEST ANSWER

You could define a cell style that with a trigger that binds to the source property of the CheckBox and sets the IsEnabled property of the cell to false when the source property returns false or true:

<Style x:Key="cellStyle" TargetType="DataGridCell">
    <Style.Triggers>
        <DataTrigger Binding="{Binding Enabled}" Value="False">
            <Setter Property="IsEnabled" Value="False" />
        </DataTrigger>
    </Style.Triggers>
</Style>

You then set the CellStyle property of all columns except the one with the CheckBox to this style:

<DataGridTextColumn ... CellStyle="{StaticResource cellStyle}">