What is best practise for IValueConverter? What is best practise for IValueConverter? wpf wpf

What is best practise for IValueConverter?


If you fail to convert (malformed values, types, ...), return DependencyProperty.UnsetValue.

It indicates that the converter produced no value and that the binding uses the FallbackValue, if available, or the default value instead.

Also, you should convert data with culture-specific conversion or invariant conversions to be on the safe side.


I personally recommend using singleton converters. Then you don't have to create an instance at every usage site, but can reference the converter like this:

Converter={x:Static SomeNamespace:SomeConverter.Instance}


You've ignored CultureInfo while parsing the string.

Always take in to account the culture info passed otherwise it would always work on Thread's CurrentCulture.

I could give some thing like "7.34,123" as input, would your code work?