I have DatePicker in DataGrid:
<DataGridTemplateColumn Header="Next Date" Width="100" >
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding NextDate, Mode=TwoWay, Converter={StaticResource dateConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DatePicker Text="{Binding NextDate, Mode=TwoWay, Converter={StaticResource dateConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
It is bound to object which defines property NextDate (NextDate is long an I use converter to go between long and DateTime):
public long NextDate
{
get { return _nextDate; }
set
{
if (_nextDate != value)
{
_nextDate = value;
NotifyPropertyChanged("NextDate");
}
}
}
The problem is that when I change date in grid, either by typing or by selecting in drop-down calendar, NextDate property does not change. Any ideas?
Try to set the UpdateSourceTrigger
in the Bindings. The following was working fine for me
PropertyChanged
for SelectedDate
LostFocus
for Text
Also, try to set a breakpoint in the converter in the debugger to be sure it gets hit
Xaml
<DataGridTemplateColumn Header="Next Date" Width="100" >
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding NextDate,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged,
Converter={StaticResource dateConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<DatePicker Text="{Binding NextDate,
Mode=TwoWay,
UpdateSourceTrigger=LostFocus,
Converter={StaticResource dateConverter}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With