XAML 中的单个字符填充
XAML 中有没有办法在单个字符周围添加填充? 最好是在角色之前和之后。
我有一个文本框,我希望输入的间隔更大一些(以便它与背景图像对齐)。 能够做类似的事情将是理想的:
有什么想法可以实现这一目标吗?
看起来可以在 MS-Word 中执行此操作(详细信息此处 ),所以希望这意味着它可以在 XAML 中实现吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过使用 可以在 XAML 中调整字符间距Glyphs 类,特别是 索引 属性。 这是一个相当低级的文本 API,因此您必须指定字体 URI(而不是家族名称),并且需要自己计算所有间距。
以下 XAML 使用 Glyph.Indices 应用字符间距:
如 记录在此处,Indices 属性包含以分号分隔的
chr,off
对列表。chr
是字体内字形的索引; 如果省略,WPF 将使用与UnicodeString
中当前字符相对应的字形。off
是该字形与下一个字形之间的间距; 0 将两个显示在彼此之上,任何正值都会增加间距。 “正常”间距取决于您使用的字体; 正如您在“Condensed”示例中看到的,我对不同的字符对使用了不同的间距,以使输出看起来更好。显然,这仅适用于您正在显示的静态文本,而不适用于从用户收集的输入(在
TextBox
中); 我不知道有什么方法可以调整“标准”文本对象中的字符间距(TextBlock
、TextBox
、Run
、等),所以答案可能是“不,在 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,off
pairs.chr
is the index of the glyph within the font; if omitted, WPF will use the glyph corresponding to the current character inUnicodeString
.off
is 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".