I want to create a TextBox that can take measurement and convert it to different units if necessary (the end result being of type double). The conversion will be controlled by a value IsMetric. If IsMetric == true then "36.5 in" would turn into 927.1 (a double representing millimeters). Conversely, if IsMetric == false then "927.1 mm" would turn into 36.5.
I thought to use an IValueConverter on a regular TextBox, but the ConverterParameter is not a DependencyProperty and therefore I can't bind IsMetric to it.
I tried IMultiValueConverter but the ConvertBack function only receives the current value of the TextBox and not all the bound values. This means I don't know IsMetric when converting the user input.
Have I missed something with the ConvertBack function? If not, then do I need to create a class derived from TextBox?
If thats the only thing you want to do, try other way to use converter parameter. But, and i would have choose this option - if your textbox has more logics in it, or tend to have more dependecie - Create custom control that inherits from textbox, and add your own dependecy properties. Then you can use your IsMetric and convert it as you want on propertychanged etc.