As you have seen, TextBlock
supports multiline text, either by setting TextWrapping
to Wrap
or by using LineBreak
instances within the content.
Two properties, LineHeight
and LineStackingStrategy
, affect how multiline text is displayed. LineHeight
determines the height of every line of text in the TextBlock
. If LineHeight
is set to a smaller value than the FontSize
property, it may cause text to be vertically cropped. Typically, you leave LineHeight
unset and rely on the default text rendering, which calculates the line height using FontSize
plus an internal padding value.
The TextBlock
class’s LineStackingStrategy
property determines the algorithm that is used to calculate line height. The LineStackingStrategy
is an enum value, which can be either MaxHeight
or BlockLineHeight
. MaxHeight
, the default strategy, calculates line height using the maximum height of any character in the font, whereas BlockLineHeight
calculates the line height using the block font design measure stored as a value in the font.
Note
If the BlockLineHeight
strategy is used, line height is calculated using the default font for the TextBlock
and the font size of any Run
elements is ignored, which can cause text to be squashed together.
18.118.195.56