HOW TO:調整段落之間的間距
這個範例顯示如何調整或消除非固定格式內容中各段落間的間距。
在非固定格式內容中,段落間所出現的多餘間格是由這些段落上所設定的邊界所致,因此,段落間的間距可藉由調整這些段落的邊界來控制。 若要完全消除兩個段落間的多餘間距,請將段落的邊界設為 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>