Parameter | Details |
---|---|
value | The value to convert from |
targetType | The type being converted to |
parameter | Optional value to control how the conversion works |
culture | CultureInfo object - required if localisation needed |
The Convert
method converts the value from the source (usually the view model) to the target (usually a property of a control).
The ConvertBack
method converts the value from the target back to the source. It is only needed if the binding is TwoWay
or OneWayToSource
.
When a ConvertBack
is not supported, i.e. there is no one-to-one mapping between the pre-conversion value and the post-conversion value, it's common practice to have the ConvertBack
method return DependencyProperty.UnsetValue
. It's a better option than throwing an exception (e.g. NotImplementedException
) as it avoids unexpected runtime errors. Also, bindings can benefit of their FallbackValue
when DependencyProperty.UnsetValue
is returned by a converter.