Padding a numeric display in WPF

前端 未结 2 912
清歌不尽
清歌不尽 2021-01-24 20:57

I\'ve got a position readout that\'s very simple -- it\'s just a TextBlock with a Style applied to it. In that Style, I just set it like so (there are more properties than this

相关标签:
2条回答
  • 2021-01-24 21:33

    I think you need something like {0,7} (display argument on seven positions, padding to the left with spaces). However, even in this case, for the text not to jump, you need to use a monospaced font, or at least a font that has the width of the space character equal to the width of the digits.

    0 讨论(0)
  • 2021-01-24 21:47

    Try {}{0,10:#,0} for a field of 10 characters.

    Note, however, that this will give odd results if the font is not fixed-width. I tried it in Kaxaml, and it works, but the text doesn't line up with a proportional font.

    0 讨论(0)
提交回复
热议问题