How to call/use a value converter inverted
Posted
by
Soko
on Stack Overflow
See other posts from Stack Overflow
or by Soko
Published on 2013-11-11T21:38:31Z
Indexed on
2013/11/11
21:53 UTC
Read the original article
Hit count: 167
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...
© Stack Overflow or respective owner