(First of all, I simplified the sample for you to understand.)
I want a editable ComboBox that shows values in inches. The original (source) value is a value in pixels (DIPs), because this is the unit in which the application works internally. The user shouldn't see the value in pixels, but in inches (the measurement unit of the UI). I determined that I must use a converter to translate from pixels to inches and viceversa.
The ComboBox items should also be formatted with "{0} in".
It should appear like this
[ 4 in |v]
[ 1 in ]
[ 2 in ]
[ 3 in ]
[ 4 in ]
But, remember, internally it should work in Pixels! and Be Editable. This is the works part. I have been totally unable to achieve this.
I have this so far:
<ComboBox IsEditable="True"
ItemStringFormat="'{}{0} in}'"
Text="{Binding RelativeSource={RelativeSource Self}, Path=SelectedValue, Mode=TwoWay, Converter={StaticResource MyPixelToInchesConverter}, StringFormat='{}{0} in}'}">
<system:Double>1</system:Double>
<system:Double>2</system:Double>
<system:Double>3</system:Double>
</ComboBox>
The problem? When you select an item, it's not formatted. And when you write a number in the editable region of the ComboBox, it's not formatted, too.
So, what is the best way for a ComboBox to format items even when the user enters a non-existent value??
Thanks!