TextBlock.FontStretch 属性

定义

获取或设置 TextBlock 的常用字体拉伸特征。Gets or sets the top-level font-stretching characteristics for the TextBlock.

public:
 property System::Windows::FontStretch FontStretch { System::Windows::FontStretch get(); void set(System::Windows::FontStretch value); };
public System.Windows.FontStretch FontStretch { get; set; }
member this.FontStretch : System.Windows.FontStretch with get, set
Public Property FontStretch As FontStretch

属性值

FontStretch 类的成员,指定要使用的字体拉伸特征。A member of the FontStretch class specifying the desired font-stretching characteristics to use. 默认值为 NormalThe default is Normal.

示例

下面的示例演示如何设置 TextBlock 元素的 FontStretch 特性。The following example shows how to set the FontStretch attribute of a TextBlock element.

<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>

下面的示例演示如何以编程方式设置 FontStretch 属性。The following example shows how to set the FontStretch property programmatically.

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

注解

对子元素上的任何 FontStretch 设置都将覆盖此顶级设置。Any FontStretch settings on child elements override this top-level setting.

此依赖属性还具有附加的属性用法。This dependency property also has an attached property usage. XAMLXAML中,使用情况是 <object TextBlock.FontStretch="value".../>的,其中object是包含在 TextBlock内的对象元素(通常是 flow 元素),FontStretch 类的字符串格式属性名称之一。In XAMLXAML, the usage is <object TextBlock.FontStretch="value".../>, where object is an object element (typically a flow element) contained within a TextBlock, and value is one of the string-format property names of the FontStretch class. 在代码中,GetFontStretchSetFontStretch支持附加的属性用法。In code, the attached property usage is supported by GetFontStretch and SetFontStretch. 附加的属性用法并不常见,因为可以包含在 TextBlock 中的大多数元素都支持一个类似的非附加 FontStretch 属性,TextBlock 用于呈现。The attached property usage is not common, because most elements that can be contained in a TextBlock support an analogous nonattached FontStretch property, which the TextBlock uses for rendering.

依赖项属性信息Dependency Property Information

标识符字段Identifier field FontStretchProperty
元数据属性设置为 trueMetadata properties set to true AffectsMeasure, AffectsRender, InheritsAffectsMeasure, AffectsRender, Inherits

适用于