Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF- "LineSpacing" in a TextBlock

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

like image 829
Xanagandr Avatar asked May 26 '14 16:05

Xanagandr


People also ask

How do I create a line break in TextBlock WPF?

Adding Line Breaks You can do this with a LineBreak inline, added as an XAML element within the text. A new line will be started at the position of this element. If you have configured the text to be justified, the final line before the line break will not be expanded to fill the available width.

Can we edit TextBlock in WPF?

TextBlock is not editable. Use TextBox instead. Save this answer.

What is the difference between TextBlock and label in WPF?

Labels usually support single line text output while the TextBlock is intended for multiline text display. For example in wpf TextBlock has a property TextWrapping which enables multiline input; Label does not have this.

What is WPF TextBlock?

The TextBlock control provides flexible text support for UI scenarios that do not require more than one paragraph of text. It supports a number of properties that enable precise control of presentation, such as FontFamily, FontSize, FontWeight, TextEffects, and TextWrapping.


1 Answers

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

like image 74
Mitch Avatar answered Sep 30 '22 08:09

Mitch