What is the use of ConvertBack method in IValueConverter interface?

前端 未结 3 1481
说谎
说谎 2020-12-09 14:38

What is the use of ConvertBack method in the IValueConverter interface.

When will it be called?

Or what is the

3条回答
  •  难免孤独
    2020-12-09 15:25

    ConvertBack is when you have mode=TwoWay on your binding.

    It converts the user input back into the datatype that you're binding to and gets invoked when the TextBox (say) loses focus.

    For example (if this wasn't built in), if you have a number that represents a price, the Convert method would take the value and format it into a string with the correct currency symbol, decimal separator etc.

    If the user types in a new value - including possible currency symbol, thousands separator etc. you'd use the ConvertBack method to parse the string and extract the numeric value.

    Another example could be credit card number input. The user could enter the number as a single string of digits or groups of digits separated by spaces or dashes. The ConvertBack method would take all these possible inputs and convert them to the single format you require.

提交回复
热议问题