8

我是 C# Wpf 的初学者,我想通过编程制作一个带有少量段落的流文档。问题是段落之间有很大的空间,我想将其调整到最小。

我通过使用 Xml 语句找到了解决方案,但我想通过编程来实现:

<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>

我该怎么做 ?。

谢谢你的帮助。

4

2 回答 2

4

尝试这个:

Style style = new Style(typeof(Paragraph));
style.Setters.Add(new Setter(Block.MarginProperty, new Thickness(0)));
myFlowDocument.Resources.Add(typeof(Paragraph), style);
于 2012-11-24T11:22:23.070 回答
2

不需要“编程”。对我有用的PagePadding属性FlowDocument

<FlowDocument PagePadding="0">

PagePadding 的 MSDN 定义

获取或设置一个值,该值指示页面边界和页面内容之间的填充空间的厚度。

于 2015-07-25T11:17:09.607 回答