I have created a datagrid with columns bound to an observable collection. All works well except for a column which is bound to a nullable decimal property from my business object.
If I use
<DataGridTextColumn Binding="{Binding Path=BaseUnitCostValue}" Header="Unit Cost Value" MinWidth="100" />
as my column definition all works well, however, as I will eventually want it to be a complex column I tried using a DatagridTemplateColumn such that
<DataGridTemplateColumn Header="Unit Cost Value" MinWidth="100">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Text="{Binding BaseUnitCostValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding BaseUnitCostValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
However, using this the column configuration, although I can enter a value as soon as I finish the edit to the cell, its value disappears.
I've also tried using converters to convert to a string and back again to a nullable decimal but with no luck.
I strongly suspect that this is something to with the fact that it's bound to a nullable decimal. Is there something more I need to do to my cellTemplates so that the value binds correctly, in the same way is does when using a standard DataGridTextColumn?
Thanks