共用方式為


如何:調整段落之間的間距

此範例示範如何調整或消除流程內容中段落之間的間距。

在流程內容中,段落之間出現的額外空間是這些段落上設定邊界的結果;因此,可以藉由調整這些段落的邊界來控制段落之間的間距。 若要完全消除兩個段落之間的額外間距,請將段落的邊界設定為 0 。 若要在整個整個 FlowDocument 段落之間達到統一間距,請使用樣式來設定 中所有段落的 FlowDocument 統一邊界值。

請務必注意,兩個相鄰段落的邊界將會「折迭」到兩個邊界的較大,而不是翻倍。 因此,如果兩個相鄰段落的邊界分別為 20 圖元和 40 圖元,則段落之間的產生空間為 40 圖元,則兩個邊界值的較大。

範例

下列範例會使用樣式將 中的所有元素的邊界 Paragraph 設定為 0 ,這可有效地消除 中 FlowDocument 段落之間的額外 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>