xaml Converters

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Parameters

ParameterDetails
valueThe value to convert from
targetTypeThe type being converted to
parameterOptional value to control how the conversion works
cultureCultureInfo object - required if localisation needed

Remarks

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.



Got any xaml Question?