如何摆脱 TextBlock 中运行之间的空白? [英] How to get rid of whitespace between Runs in TextBlock?
问题描述
我有以下 XAML:
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"
FontSize="10" FontFamily="Arial" Foreground="#414141">
<Run Text="{Binding LoadsCount}" />
<Run Text="+" />
<Run Text="{Binding BrokerLoadsCount}" />
</TextBlock>
我得到这样的显示:12 + 11
它以某种方式在每个 Run
之间插入额外的空间如何让它显示 12+11
?
And I get display like this: 12 + 11
Somehow it inserts extra space between each Run
How do I make it display 12+11
?
推荐答案
run 标签之间的空格导致空格,这是最简单的解决方法.
The spaces between the run tags cause the spaces, this is the easiest fix.
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="10"
FontFamily="Arial"
Foreground="#414141">
<Run Text="{Binding LoadsCount}" /><Run Text="+" /><Run Text="{Binding BrokerLoadsCount}" />
</TextBlock>
因为 <TextBlock>
和 </TextBlock>
之间的任何东西都是针对 TextBlock 的 text 属性,所以运行之间的中断处的空白会导致效果你看.您也可以将其缩短为这样.
Because anything between the <TextBlock>
and </TextBlock>
is targeting the text property of the TextBlock the whitespace from the breaks between the runs causes the effect you see. You could also shorten it to this.
<Run Text="{Binding LoadsCount}" />+<Run Text="{Binding BrokerLoadsCount}" />
这篇 MSDN 文章详细介绍了 xaml 如何处理空格
This MSDN article gives all the specifics on how xaml handles the whitespace
http://msdn.microsoft.com/en-us/library/ms788746.aspx
如果您想知道为什么一个中断和大量制表符会转化为一个空格
If you were curious why a break and a ton of tabs translates into a single space
所有空白字符(空格、换行、制表符)都转换为空格.
All whitespace characters (space, linefeed, tab) are converted into spaces.
删除所有连续的空格并替换为一个空格
All consecutive spaces are deleted and replaced by one space
这篇关于如何摆脱 TextBlock 中运行之间的空白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!