Using StringFormat in a Binding to display Hex value with spaces

一曲冷凌霜 提交于 2019-11-30 19:02:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!