What is the use of ConvertBack method in the IValueConverter interface.
When will it be called?
Or what is the order of invocation of the Convert and ConvertBack methods?
I have asked the question here because: I have bound one property of codebehind to TEXTBOX’s TEXT Property and am using convertor for that property. The first Convert Method invokes and when I change TEXT in TEXTBOX nothing happens… but as soon as I close the form the ConvertBack method invokes.
IMO, the
ConvertBackmethod is used to convert your visual representation of the data to the specific DataType.For example: you use a Converter to convert a boolean
trueto the string"TrueBoolean". This text will be displayed in your TextBox. When you change the value of the TextBox, theConvertBackmethod will be called as soon as the binding fires again (default OnFocusLost). Now yourConvertBackmethod will try to convert the new value to the datatype you want it to be. So you will have to implement logic to convert"FalseBoolean"tofalse.This technique is used a lot in DataGrids if I’m not mistaken.
Hope this is a bit clear…
UPDATE
About you question in the comment:
To overwrite the default
OnFocusLostbinding behavior you have to change your binding like this: