TextElement.FontStretch Property

Definition

Gets or sets the font-stretching characteristics for the content of the element.

C#
public System.Windows.FontStretch FontStretch { get; set; }

Property Value

The desired font-stretching characteristics to use. The default is Normal.

Examples

The following example shows how to set the FontStretch attribute, using Paragraph as the example element.

XAML
<Paragraph
  FontFamily="Century Gothic, Courier New"  
  FontSize="16pt"
  FontStretch="UltraExpanded"
  FontStyle="Italic"
  FontWeight="DemiBold"
>
  <Run>
    This text will use the Century Gothic font (if available), with fallback to Courier New.  It 
    will render with a font size of 16 points in ultra-expanded demi-bold italic.
  </Run>
</Paragraph>

The following figure shows how the preceding example renders.

Screenshot: Text with text properties set

The following example shows how to set the FontStretch property programmatically.

C#
Run run = new Run(
    "This text will use the Century Gothic font (if available), with fallback to Courier New."
    + "It will render with a font size of 16 pixels in ultra-expanded demi-bold italic.");
Paragraph par = new Paragraph(run);

par.FontFamily = new FontFamily("Century Gothic, Courier New");
par.FontSize = 16;
par.FontStretch = FontStretches.UltraExpanded;
par.FontStyle = FontStyles.Italic;
par.FontWeight = FontWeights.DemiBold;

Remarks

This dependency property also has an attached property usage. In XAML, the usage is <object TextElement.FontStretch="value".../>, where object is an object element (typically a flow element) contained within a TextElement, and value is one of the string-format property names of the FontStretch class. In code, the attached property usage is supported by the GetFontStretch and SetFontStretch methods. The attached property usage is not common, because most elements that can be contained in a TextElement support an analogous nonattached FontStretch property, which the content host uses for rendering.

Dependency Property Information

Item Value
Identifier field FontStretchProperty
Metadata properties set to true AffectsMeasure, AffectsRender, Inherits

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10