views:

1100

answers:

2

I have a checkbox column bound to a dependency property. When editing the checked property is it possible to update the bound property immediately rather than waiting for the cell to lose focus?

Thanks, Mark

+3  A: 

Hello,

you can look here, there is a solution (go to: Creating an AutoCommitCheckBoxColumn)

summary:

derive from DataGridCheckBoxColumn & handle checkBox_Checked & checkBox_Unchecked events.

public class AutoCommitCheckBoxColumn : DataGridCheckBoxColumn
{
    private void checkBox_Unchecked(object sender, RoutedEventArgs e)
    {
        CommitCellEdit((FrameworkElement)sender);
    }

    private void checkBox_Checked(object sender, RoutedEventArgs e)
    {
        CommitCellEdit((FrameworkElement)sender);
    }

    protected override FrameworkElement GenerateEditingElement(
        DataGridCell cell, object dataItem)
    {
        var checkBox = (CheckBox)base.GenerateEditingElement(cell, dataItem);

        checkBox.Checked += checkBox_Checked;
        checkBox.Unchecked += checkBox_Unchecked;

        return checkBox;
    }
}
najmeddine
A: 

You can try to handle OnKeyDown and OnKeyUp events but you'll have to update the bound property yourself.

Vitalik