11

I know that when data is about to be displayed, Convert() method is called to convert the data and the converted data is displayed instead.

I'm wondering when ConvertBack() method gets called? What is its purpose?

I've a DataGrid whose ItemSource is binded to some collection, and I've implemented IValueConverter for one property of items in the collection. When I make IsReadOnly="True" (in the DataGrid), then ConvertBack method is called if I double-click on the cell (for which IValueConverter is implemented) and then change the focus. But when I make IsReadOnly="False", then ConvertBack method is never called, no matter what I do with the DataGrid and its cells.

Please explain this behavior of DataGrid cells and ConvertBack method of IValueConverter.

Nawaz
  • 353,942
  • 115
  • 666
  • 851
  • 1
    It is called when the binding mode is TwoWay (default mode for TextBox.Text and probably for CheckBox.IsChecked). If you set OneWay explicitly , the method will not be called, I think. – vortexwolf Mar 23 '11 at 13:16
  • I'm having this problem too. If I bind directly to a `DataTable` the source gets updated on `CellEditEnding`. If I bind to a different kind of object and use a converter in the binding to convert it to a `DataTable` on the fly `ConvertBack` never gets called. Meaning user edits don't get propagated to the source. I'm wondering if I need to derive my own `DataTable`and add some kind of notification logic to it. Will post if I find a solution. – Phil Gan May 11 '11 at 09:44

1 Answers1

8

"The data binding engine calls this method when it propagates a value from the binding target to the binding source."

see msdn

you should post your binding for your cell with the valueconverter

blindmeis
  • 22,175
  • 7
  • 55
  • 74