Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decrease line spacing in a TextBlock / FlowDocument

Some fonts have a large amount of whitespace above and below the characters. Is there a way to correct for that, and tighten up the space between lines of a word-wrapped paragraph in WPF (in either a TextBlock or a FlowDocument)? Kind of like a negative margin between lines?

There's a LineHeight property on Paragraph and TextBlock, but it only seems to let you increase the spacing -- if you set it to a smaller value than the default, it's simply ignored.

like image 834
Joe White Avatar asked Aug 10 '09 12:08

Joe White


2 Answers

Set the LineHeight like before, but change the LineStackingStrategy to BlockLineHeight

like image 123
Joel Avatar answered Nov 04 '22 11:11

Joel


To exemplify @Joel's answer (which is still very useful 5 years later :P)

    <StackPanel VerticalAlignment="Center">
        <Button Width="137" Height="47.96">
            <TextBlock Text="This is a very long text that gets cut because it is so long" TextWrapping="Wrap"/>
        </Button>
        <Button Width="137" Height="47.96">
            <TextBlock Text="This is a very long text that doesn't cut thanks to @Joel" TextWrapping="Wrap" 
                LineStackingStrategy="BlockLineHeight" LineHeight="13"/>
        </Button>
    </StackPanel>
like image 38
johnildergleidisson Avatar answered Nov 04 '22 11:11

johnildergleidisson