Sinatr
Sinatr

Reputation: 21969

DataGridTemplateColumn binding

I want to have custom column in DataGrid:

<DataGridTemplateColumn Header="Click">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox IsChecked="{Binding IsChecked}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

However, clicking CheckBox (check/uncheck) doesn't trigger property setter

bool _isChecked;
public bool IsChecked
{
    get { return _isChecked; }
    set
    {
        _isChecked = value; // setting breakpoint here
        OnPropertyChanged();
    }
}

The setter sometimes get called and I fail understand when exactly it happens: when I switch row? when I double-click another cell? Or what?

If I use ListView then binding is triggered immediately.

My question: what is going on? How to make setter called as soon as I tick/untick CheckBox?

Upvotes: 1

Views: 95

Answers (1)

Mr.B
Mr.B

Reputation: 3787

<CheckBox IsChecked="{Binding IsChecked,UpdateSourceTrigger=PropertyChanged}" />

Should fix your problem.

Upvotes: 3

Related Questions