我是C#Wpf的初学者,我想通过编程制作一个几乎没有paragrah的流程文档。 问题是pagraph之间有一个很大的空间,我想把它调整到最小。
我通过使用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>
我该怎么做?。
感谢你的帮助。
答案 0 :(得分:2)
试试这个:
Style style = new Style(typeof(Paragraph));
style.Setters.Add(new Setter(Block.MarginProperty, new Thickness(0)));
myFlowDocument.Resources.Add(typeof(Paragraph), style);
答案 1 :(得分:1)
不需要“编程”。 PagePadding
上的FlowDocument
属性为我工作:
<FlowDocument PagePadding="0">
MSDN definition for PagePadding:
获取或设置一个值,该值指示页面边界与页面内容之间的填充空间的厚度。