此示例演示如何调整或消除流内容中段落之间的间距。
在流内容中,段落之间出现的额外空间是在这些段落上设置的边距的结果;因此,可以通过调整这些段落的边距来控制段落之间的间距。 若要完全消除两个段落之间的额外间距,请将段落的边距设置为 0。 若要在整个整个 FlowDocument段落之间实现统一间距,请使用样式设置所有段落的 FlowDocument统一边距值。
请务必注意,两个相邻段落的边距将“折叠”到两个边距中的较大位置,而不是翻倍。 因此,如果两个相邻段落的边距分别为 20 像素和 40 像素,则段落之间的结果空间为 40 像素,这两个边距值越大。
示例:
下面的示例使用样式将 FlowDocument 中所有 Paragraph 元素的边距设置为 0,从而有效地消除了 FlowDocument 中段落之间的额外间距。
<FlowDocument>
<FlowDocument.Resources>
<!-- This style is used to set the margins for all paragraphs in the FlowDocument to 0. -->
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/>
</Style>
</FlowDocument.Resources>
<Paragraph>
Spacing between paragraphs is caused by margins set on the paragraphs. Two adjacent margins
will "collapse" to the larger of the two margin widths, rather than doubling up.
</Paragraph>
<Paragraph>
To eliminate extra spacing between two paragraphs, just set the paragraph margins to 0.
</Paragraph>
</FlowDocument>