How to adjust the space between paragraph in a flow document by programming

安稳与你 提交于 2020-01-03 13:00:06

问题


I'm a beginer in C# Wpf and I want to make a flow document with few paragrah by programming. The problem is that there is a big space between pagraphs and i want to resize it to its minimum.

I found a solution by using a Xml statement, but i want to make it by programming :

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

How can i do it ?.

thanx for you're help.


回答1:


Try this:

Style style = new Style(typeof(Paragraph));
style.Setters.Add(new Setter(Block.MarginProperty, new Thickness(0)));
myFlowDocument.Resources.Add(typeof(Paragraph), style);



回答2:


No "programming" is necessary. The PagePadding property on FlowDocument worked for me:

<FlowDocument PagePadding="0">

MSDN definition for PagePadding:

Gets or sets a value that indicates the thickness of padding space between the boundaries of a page and the page's content.



来源:https://stackoverflow.com/questions/13540656/how-to-adjust-the-space-between-paragraph-in-a-flow-document-by-programming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!