How to call/use a value converter inverted
- by Soko
Is it possible to use a converter the "wrong" way around?
In other words: can I swap source and target?
Here's an example:
I created a simple IValueConverter called NullableDecimalToStringConverter which converts an input if "" into null and a number into decimal.
I use it to bind a TextBox in my WPF view to a decimal? property in my ViewModel.
In another context I'd like to convert a NullableDecimal into a String in the same way...
Is it possible to simply use the existing NullableDecimalToStringConverter inverted?
One method is to use the parameter of the converter to tell the converter which way it should convert.
But is there a .NET build in way to do such a thing?
Another way would be to build a base class with both conversion methods and two separate converter which call the base class methods...