wpf datagrid enter to edit

╄→гoц情女王★ 提交于 2019-12-11 01:02:11

问题


I hope this is a simple one. I have a datagrid in a wpf application. one of the columns is a checkbox column. the user can only check the checkbox if the cell is already selected. so in effect to check any box the user has to double click, once to select, then once more to check the box. I want the user to be able to just check the box right a way with a single click. I couldn't find any obvious properties to make this happen. what's the best way to go about doing this?


回答1:


For other answers see this SO post but the answer I liked was way at the bottom so I'll repeat it here with some more detail.

That answer was: don't use a DataGridCheckBoxColumn. It's almost no more work to just put a Checkbox in a DataGridTemplate Column. When you do this it responds to a single click exactly like you want. In the example below IsSelected is just a custom bool property on my ViewModel, everything else is pure xaml.

<DataGridTemplateColumn>
  <DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
        <CheckBox  IsChecked="{Binding IsSelected, UpdateSourceTrigger=PropertyChanged}" />
    </DataTemplate>
  </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>


来源:https://stackoverflow.com/questions/6336868/wpf-datagrid-enter-to-edit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!