How to get rid of space from a paragraph? I have tried using negative margin/padding
but it doesn't accept negative values for these properties. Any idea?
My code is mentioned below:
<FlowDocument>
<Section>
<Paragraph>1</Paragraph>
<Paragraph>2</Paragraph>
<Paragraph></Paragraph>
<Paragraph>4</Paragraph>
</Section>
</FlowDocument>
And, outputs for the above code is given below:
EDIT: Here is an example that would make a bit more sense(as per the comments):
<FlowDocument>
<Section>
<Paragraph>
<TextBlock Text="1" Visibility="Visible"/>
</Paragraph>
<Paragraph>
<TextBlock Text="2" Visibility="Visible"/>
</Paragraph>
<Paragraph>
<TextBlock Text="3" Visibility="Collapsed"/>
</Paragraph>
<Paragraph>
<TextBlock Text="4" Visibility="Visible"/>
</Paragraph>
</Section>
</FlowDocument>
Which makes the exact same result.
I hesitate to post this, as I'm sure there must be a better way, but since no-one else has replied....
A flow document
Section
appears to wrap paragraphs with whitespace equivilent to the paragraph'sLineHeight
.LineHeight
cannot be 0, but it can be very small. SettingLineHeight
on theSection
will remove whitespace around ALL paragraphs.Setting
LineHeight
like this will generally not affect the text inside the paragraphs, because the defaultLineStackingStrategy
uses the height of the font instead. Note how the blank Paragraph still has height.You might think setting
LineHeight
only on the blank paragraph would work, butSection
will still honour the whitespace of the preceeding paragraph. Since the preceding paragraph has normalLineHeight
, you still get the margin.So, in order to remove your blank paragraph completely, you need to set
LineHeight
on the blank AND the preceeding paragraph, and tell your blank paragraph to use theLineHeight
as its block height:I tried to write a trigger that would do this automatically for blank paragraphs, but unfortunately
Paragraph.Inlines.Count
is not a DependencyProperty, and trying to use it to detect blank paragraphs is unreliable depending on when the paragraph gets populated.