I am shy about posting this since I'm sure there should be a better way, but since no one answered ...
The Section stream document appears to contain paragraphs with a space equivalent to the LineHeight paragraph.
LineHeight cannot be 0, but can be very small. Setting LineHeight to Section will remove spaces around ALL paragraphs.
<FlowDocumentScrollViewer> <FlowDocumentScrollViewer.Resources> <Style TargetType="Paragraph"> <Setter Property="Background" Value="LightBlue" /> </Style> </FlowDocumentScrollViewer.Resources> <FlowDocument> <Section LineHeight="0.1"> <Paragraph>1</Paragraph> <Paragraph>2</Paragraph> <Paragraph/> <Paragraph>4</Paragraph> <Paragraph>5</Paragraph> </Section> </FlowDocument> </FlowDocumentScrollViewer>

Setting LineHeight like this usually does not affect the text inside the paragraphs, because by default LineStackingStrategy uses font height instead. Note that the empty paragraph still has a height.
You might think that setting LineHeight only in an empty paragraph would work, but Section would still respect the spaces of the previous paragraph. Since the previous paragraph has a normal LineHeight , you still get the difference.
So, in order to completely remove the empty paragraph, you need to set LineHeight to the space and the previous paragraph, and your empty paragraph to use LineHeight as its block height:
<FlowDocumentScrollViewer> <FlowDocumentScrollViewer.Resources> <Style TargetType="Paragraph"> <Setter Property="Background" Value="LightBlue" /> </Style> </FlowDocumentScrollViewer.Resources> <FlowDocument> <Section> <Paragraph>1</Paragraph> <Paragraph LineHeight="0.1">2</Paragraph> <Paragraph LineHeight="0.1" LineStackingStrategy="BlockLineHeight"/> <Paragraph>4</Paragraph> <Paragraph>5</Paragraph> </Section> </FlowDocument> </FlowDocumentScrollViewer>

I tried to write a trigger that would do this automatically for empty paragraphs, but unfortunately Paragraph.Inlines.Count not a DependencyProperty, and trying to use it to detect empty paragraphs is unreliable depending on when the paragraph is filled.
GazTheDestroyer
source share