问题
I haven't been able to figure out how to use StringFormat to display hex as:
08 A4 23 F5
Specifically I want the spaces after every 2 characters. When I do this:
Text="{Binding MyIntValue, StringFormat={}{0:x}}"
It looks like this:
08A423F5
My backup plan is using a converter on the binding but I would like to know if is possible to do it with just StringFormat.
回答1:
Based on what the documentation says about the The hexadecimal ("X") format specifier
and after having a play with Custom Numeric Format Strings, I don't think this is possible in quite way you're after.
I think you'll either have to use a Converter
like you suggested (probably making use of a BitConverter
). Or just exposing a string property formatted in the way you desire.
来源:https://stackoverflow.com/questions/21388089/using-stringformat-in-a-binding-to-display-hex-value-with-spaces