TextBlock.LineHeight 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置每行内容的高度。
public:
property double LineHeight { double get(); void set(double value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.LengthConverter))]
public double LineHeight { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.LengthConverter))>]
member this.LineHeight : double with get, set
Public Property LineHeight As Double
属性值
线条的高度(以设备无关像素为单位),范围为 0.0034 到 160000。 值 NaN (等效于属性值为“”Auto)表示行高是从当前字体特征自动确定的。 默认值为 NaN。
- 属性
例外
LineHeight 设置为非正值。
示例
以下示例演示如何设置 LineHeight 元素的属性 TextBlock 。
<TextBlock
Name="textBlock"
Background="AntiqueWhite"
Foreground="Navy"
FontFamily="Century Gothic"
FontSize="12"
FontStretch="UltraExpanded"
FontStyle="Italic"
FontWeight="UltraBold"
LineHeight="Auto"
Padding="5,10,5,10"
TextAlignment="Center"
TextWrapping="Wrap"
Typography.NumeralStyle="OldStyle"
Typography.SlashedZero="True"
>
<Run Background="LightGreen">Text run 1.</Run>
<LineBreak/><Run Background="LightBlue">Text run 2.</Run>
<LineBreak/><Run Background="LightYellow">Text run 3.</Run>
</TextBlock>
以下示例演示如何以编程方式设置 LineHeight 属性。
TextBlock textBlock = new TextBlock(new Run("A bit of text content..."));
textBlock.Background = Brushes.AntiqueWhite;
textBlock.Foreground = Brushes.Navy;
textBlock.FontFamily = new FontFamily("Century Gothic");
textBlock.FontSize = 12;
textBlock.FontStretch = FontStretches.UltraExpanded;
textBlock.FontStyle = FontStyles.Italic;
textBlock.FontWeight = FontWeights.UltraBold;
textBlock.LineHeight = Double.NaN;
textBlock.Padding = new Thickness(5, 10, 5, 10);
textBlock.TextAlignment = TextAlignment.Center;
textBlock.TextWrapping = TextWrapping.Wrap;
textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle;
textBlock.Typography.SlashedZero = true;
Dim textBlock As New TextBlock(New Run("A bit of text content..."))
textBlock.Background = Brushes.AntiqueWhite
textBlock.Foreground = Brushes.Navy
textBlock.FontFamily = New FontFamily("Century Gothic")
textBlock.FontSize = 12
textBlock.FontStretch = FontStretches.UltraExpanded
textBlock.FontStyle = FontStyles.Italic
textBlock.FontWeight = FontWeights.UltraBold
textBlock.LineHeight = Double.NaN
textBlock.Padding = New Thickness(5, 10, 5, 10)
textBlock.TextAlignment = TextAlignment.Center
textBlock.TextWrapping = TextWrapping.Wrap
textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle
textBlock.Typography.SlashedZero = True
注解
更改此值不会更改关联文本的高度;而是更改包含文本的行的高度。 若要更改文本的大小,请使用 FontSize 属性。
除此属性外,行 TextBlock 的布局也受其 LineStackingStrategy 属性的影响。
此依赖属性还具有附加的属性用法。 在 XAML 中,用法是 <object TextBlock.LineHeight="value".../>,其中 对象 是包含在对象 TextBlock元素(通常是流元素)中, 值 是 XAML 值中所述的字符串。 在代码中,附加属性用法受 GetLineHeight 和 SetLineHeight支持。 附加属性用法并不常见。
XAML 属性用法
<object LineHeight="double"/>
- or -
<object LineHeight="qualifiedDouble"/>
- or -
<object LineHeight="Auto"/>
XAML 值
一个 Double 值等于或大于 0.0034 或等于或等于或小于或小于 160000的字符串表示形式。 不限定的值以与设备无关的像素进行度量。 字符串不需要显式包含小数点。
qualifiedDouble如上所述的双精度值(除外Auto)后跟以下单位说明符之一:px、、in、cmpt。
px (默认值) 是独立于设备的单位(每单位 1/96 英寸)
in 为英寸;1in==96px
cm 为厘米;1cm==(96/2.54) px
pt is points;1pt==(96/72) px
自动使行高从当前字体特征自动确定。 等效于属性值为 Double.NaN.
Dependency 属性信息
| 物品 | 价值 |
|---|---|
| 标识符字段 | LineHeightProperty |
元数据属性设置为 true |
AffectsMeasure、AffectsRender、Inherits |