Sinatr Sinatr - 2 months ago 43
C# Question

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
?

Answer

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

Should fix your problem.

Comments