views:

392

answers:

1
+3  A: 

I don't like using the DataGridCheckBoxColumn because it needs to have focus before you can interact with the checkbox. So I instead put a CheckBox inside a template column and you only need one click to change state.

<dg:DataGridTemplateColumn Width="SizeToHeader">
    <dg:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding Path=Selected}" Margin="2,0,2,0" />
        </DataTemplate>
    </dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>

However, if you actually want the checkbox to change state when they click anywhere in the cell (and not just on the checkbox) you can use the following code, which makes the CheckBox control take up the entire size of the cell.

<dg:DataGridTemplateColumn Width="SizeToHeader">
    <dg:DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding Path=Selected}" Margin="2,0,2,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
        </DataTemplate>
    </dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
viggity
Thanks, I don't mind if they have to click directly on the chcekbox. what I don't want is having to get the focus to be able to click it.
David Brunelle