在绑定中使用StringFormat以显示带空格的十六进制值 [英] Using StringFormat in a Binding to display Hex value with spaces
问题描述
我一直无法弄清楚如何使用StringFormat将十六进制显示为:
I haven't been able to figure out how to use StringFormat to display hex as:
08 A4 23 F5
具体来说,我希望每2个字符后有一个空格.当我这样做时:
Specifically I want the spaces after every 2 characters. When I do this:
Text="{Binding MyIntValue, StringFormat={}{0:x}}"
它看起来像这样:
08A423F5
我的备份计划在绑定上使用转换器,但是我想知道是否可以仅使用StringFormat做到这一点.
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.
推荐答案
基于,并在玩过
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.
我认为您要么必须像建议的那样使用Converter
(可能使用BitConverter
).或者只是公开以您期望的方式格式化的字符串属性.
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.
这篇关于在绑定中使用StringFormat以显示带空格的十六进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!