Export (0) Print
Expand All

TextElement.FontStyle Property

Gets or sets the font style for the content of the element.

Namespace:  System.Windows.Documents
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public FontStyle FontStyle { get; set; }
<object FontStyle="FontStyle" .../>

Property Value

Type: System.Windows.FontStyle
A member of the FontStyles class that specifies the desired font style. The default is determined by the SystemFonts.MessageFontStyle value.

This dependency property also has an attached property usage. In XAML, the usage is <object TextElement.FontStyle="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 in the FontStyles class. In code, the attached property usage is supported by the GetFontStyle and SetFontStyle methods. The attached property usage is not common, because most elements that can be contained in a TextElement support an analogous nonattached FontStyle property, which the content host uses for rendering.

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


<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 FontStyle property programmatically.


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;


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft