方法: 段落間の間隔を調整する

この例では、フロー コンテンツ内の段落間の間隔を調整または削除する方法を示しています。

フロー コンテンツでは、段落に設定した余白に応じて、段落間に余分なスペースが表示されます。つまり、それらの段落間の間隔を調整することで、段落間の間隔を制御できます。 2 つの段落間の余分なスペースを全体でなくすには、段落の余白を 0 に設定します。 FlowDocument 全体で段落間の間隔を同じにするには、スタイルを使用して、FlowDocument 内のすべての段落に同じ余白値を設定します。

2 つの隣接する段落の余白は、倍になるのではなく、2 つの余白の大きい方に "折りたたまれる" という点にご注意ください。 つまり、2 つの隣接する段落の余白がそれぞれ 20 ピクセルと 40 ピクセルであった場合、段落間の間隔は 2 つの余白の大きい方の 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>