Has anyone ever actually implemented this function?
Yes.
Oh, I'm sorry. Did you want something more than that? :)
You have misunderstood the question you're referencing. The question itself makes clear that their specific scenario has no meaningful use for the ConvertBack()
method, and they are asking what the method should do in that specific case. The posted answer addresses that specific case, not every single implementation of IMultiValueConverter
.
I have certainly implemented the method myself with actual logic in the past. A couple of examples where you might find doing so useful are:
- A converter that merges three color components – red, green, and blue – into a single
Color
value for binding to some type of color-picker control. The Convert()
method would compose the three channels into the single Color
value, while the ConvertBack()
method would decompose the Color
value back to three constituent properties.
- A converter that formats a time value represented as three different properties – hours, minutes, and seconds – as a text string with the format
"HH:MM:SS"
. The Convert()
method would combine the values with the ':'
separator character, while the ConvertBack()
method would split the values apart and parse them back as their original integer values.
Those are just a couple of reasonable examples. Of course in the real-world, there are countless reasons one might actually provide a real implementation for the ConvertBack()
method.
Of course, there are just as many scenarios where the binding is one-way only, and there's no meaningful way to implement the ConvertBack()
method. For those scenarios, throw NotSupportedException()
, just as the referenced Q&A suggests.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…