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
Sectionappears to wrap paragraphs with whitespace equivilent to the paragraph'sLineHeight.LineHeightcannot be 0, but it can be very small. SettingLineHeighton theSectionwill remove whitespace around ALL paragraphs.Setting
LineHeightlike this will generally not affect the text inside the paragraphs, because the defaultLineStackingStrategyuses the height of the font instead. Note how the blank Paragraph still has height.You might think setting
LineHeightonly on the blank paragraph would work, butSectionwill 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
LineHeighton the blank AND the preceeding paragraph, and tell your blank paragraph to use theLineHeightas its block height:I tried to write a trigger that would do this automatically for blank paragraphs, but unfortunately
Paragraph.Inlines.Countis not a DependencyProperty, and trying to use it to detect blank paragraphs is unreliable depending on when the paragraph gets populated.