WPF- "LineSpacing" in a TextBlock
Asked Answered
S

1

8

I have a TextBlock I would like to pass a property of 'LineSpacing'. The thing with using "LineHeight" with LineStackingStrategy="BlockLineHeight" is that it also applies the LineHeight to the segment before the first line:

TextblockEx

How can I manage to preserve said 'LineSpacing' without modifying the LineHeight before the first line?

One thing I though might work is to separate each line in a Paragraph of a FlowDocument, since the Paragraph has a property Spacing Before Line and Spacing After Line.

Any help would be truly appreciated. Thanks in advance.

ANSWER

It seems that you can use LineStackingStrategy="MaxHeight" to avoid having leading on the first line. (Check answers below for full details).

P.S. Thanks to Mitch for the revelation :D

Samul answered 26/5, 2014 at 16:36 Comment(3)
One easy thing you could do, is fake it. Just apply a small negative margin to the whole object to negate the line-spacing on the top and bottom. Like throw Margin="0,-5" on your TextBlock , such a short answer didn't think it warranted as more than a comment.Demurral
Not sure if this answer: #325575 applies to your question, or could be adapted, but might be worth a read.Storeroom
Actually, that was my initial approach. I didn't want to keep up with it since it was causing me problems trying to calculate the margins for all the different options (Since the user can modify the TextSize and the TextFont, my calculations for the LineHeight method involves getting this 2 parameters to work in a function to calculate the LineSpacing, but down the line some combinations just don't quite fit (I believe is because of the decimals), but using another number format doesn't seem to work, either.Samul
V
12

It seems that you can use LineStackingStrategy="MaxHeight" to avoid having leading on the first line:

<TextBlock LineStackingStrategy="MaxHeight" TextWrapping="Wrap" LineHeight="50">Lorem...</TextBlock>

Produces

MaxHeight

Vada answered 26/5, 2014 at 22:1 Comment(1)
@Xanagandr, if this answers your question, you can mark it accepted by clicking the check-mark under the voting buttons. meta.stackexchange.com/questions/5234/…Vada

© 2022 - 2024 — McMap. All rights reserved.