Is there a way in XAML to add padding around individual characters? Preferably before and after the character.
I have a textbox that I would like the input to be spaced out a bit more (so it aligns with a background image). It would be ideal to be able to do something like:
Any ideas how one can accomplish this?
It looks like one can do this in MS-Word (details here), so hopefully that means it is possible in XAML?
Adjusting inter-character spacing is possible in XAML by using the Glyphs class, specifically the Indices property. This is a pretty low-level text API, so you have to specify the font URI (rather than the family name), and you need to calculate all the spacings yourself.
The following XAML uses Glyph.Indices to apply inter-character spacing:
As documented here, the Indices property contains a semicolon-delimited list of
chr,offpairs.chris the index of the glyph within the font; if omitted, WPF will use the glyph corresponding to the current character inUnicodeString.offis the spacing between this glyph and the next; 0 displays the two on top of each other, any positive value increases the spacing. The “normal” spacing will depend on the font you’re using; as you can see in the “Condensed” example, I used a different spacing for different pairs of characters to make the output look better.Clearly this only applies to static text that you are displaying, and not input being collected from the user (in a
TextBox); I don’t know of any way to adjust the inter-character spacing in the “standard” text objects (TextBlock,TextBox,Run, etc.), so perhaps the answer is “No, there is not a way to do this in XAML”.