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

フロー コンテンツ内の段落間の間隔を調整する、または間隔をなくす方法を次の例に示します。

フロー コンテンツの段落間に余分な間隔が空くのは、段落にマージンが設定されているからです。したがって、段落間の間隔を制御するには、段落のマージンを調整します。 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>