Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datagrid no double click to edit columns

I am using a WPF DataGrid in a simple Window to display some Data provided by a Model.

<DataGrid x:Name="unitTable" ItemsSource="{Binding Units}" AutoGenerateColumns="False">
    <DataGrid.Columns>
         <DataGridCheckBoxColumn Binding="{Binding Path=IsChosen, Mode=TwoWay}" Header="Chosen"></DataGridCheckBoxColumn>
         <DataGridTextColumn Binding="{Binding Path=Name, Mode=TwoWay}" Header="Name"></DataGridTextColumn>
         <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path=IsActive, Mode=TwoWay, Converter={StaticResource boolToActive}}" Header="Active"></DataGridTextColumn>
    </DataGrid.Columns>
</DataGrid>

Everything worked perfectly fine with the model, but there was this problem where I had to double click the columns to edit the value of the checkboxes for example.

I came up with this solution:

<Style TargetType="DataGridCell" x:Key="NoDoubleClick">
      <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                 <Setter Property="IsEditing" Value="True" />
            </Trigger>
      </Style.Triggers>
</Style>

And after I assigned the style to the Checkbox- and the first TextColumn it actually worked :) After a while I realized, that the model doesn't get updated anymore when the Style "NoDoubleClick" was assigned to a column.

Can anybody tell me what I am doing wrong?

like image 996
Lorenz Killer Avatar asked Dec 12 '25 19:12

Lorenz Killer


1 Answers

DataGridColumns usually only update the bound data when the edited cells lose focus. To get around this and make it work with your Style, set the UpdateSourceTrigger of your Binding to PropertyChanged.

like image 104
Manfred Radlwimmer Avatar answered Dec 14 '25 22:12

Manfred Radlwimmer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!