简体   繁体   中英

Immediate action after checking checkbox in GridView

I'm developing a MVVM-based system with DevExpress WPF controls and Simple MVVM Toolkit. There is a case where I am displaying a GridControl where the viewmodel of each row in the grid has got a boolean property (among others). This property is displayed in the GridControl as a checkbox.

I want to update another view in the window right after the user selects or deselects that checkbox, but that does not seem to work. I have put some code in the property setter that would update the view but this is only executed after the user clicks outside of the GridControl's row. So it takes 2 steps to execute the setter:

  1. Select or deselect the checkbox
  2. Click to select another row in the gridcontrol

Can I have the setter executed right after step 1?

I can imagine it has got something to do with the Simple MVVM Tooklkit behavior that when a viewmodel is in its "editing" state, it is cloned and only when the "editing" state is ended, the properties are set to the new values.

I'd appreciate any insights on this.

Best regards, ~Rob

This has been discussed here several times. Just use a DataGridTemplateColumn like this:

    <DataGridTemplateColumn Width="Auto" Header="Selected">
      <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
          <Grid>
            <CheckBox IsChecked="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                            HorizontalAlignment="Center" 
                            VerticalAlignment="Center"/>
          </Grid>
        </DataTemplate>
      </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM