Export (0) Print
Expand All

TextElement.FontFamily Property

Gets or sets the preferred top-level font family for the content in this element.

Namespace: System.Windows.Documents
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

[LocalizabilityAttribute(LocalizationCategory.Font, Modifiability=Modifiability.Unmodifiable)] 
public FontFamily FontFamily { get; set; }
/** @property */
public FontFamily get_FontFamily ()

/** @property */
public void set_FontFamily (FontFamily value)

public function get FontFamily () : FontFamily

public function set FontFamily (value : FontFamily)

<object>
  <object.FontFamily>
    <FontFamily .../>
  </object.FontFamily>
</object>
<object FontFamily="fontFamilyName"/>
- or -
<object FontFamily="fontFamilyNamesList"/>
- or -
<object FontFamily="fontFamilyFolderReference"/>
- or -
<object FontFamily="fontFamilyUriReference"/>
 fontFamilyName  A string specifying a font family name.  For example, "Arial" or "Century Gothic".  fontFamilyNamesList  A string specifying multiple font family names, each separated by a comma (any whitespace following a comma is ignored).  The first font family specified serves as the primary font family; subsequent font families serve as fallback families to be used in cases where the primary font family is unavailable or not applicable.  For example, "Arial, Century Gothic" specifies Arial as the primary font family, with Century Gothic as the fallback font family.  fontFamilyFolderReference  A string specifying a folder containing the font, along with a font family name.  The folder and font family name are delimited by a # character.  The folder reference may be absolute, or relative.  For example, "Custom Fonts\#My Custom Font".  fontFamilyUriReference  A string specifying a uniform resource identifier (URI) for the font, along with a font family name.  The URI and font family name are delimited by a # character.  For example, "http://MyFontServer/Fonts/#My Custom Font". 

Property Value

A FontFamily object specifying the preferred font family, or a primary preferred font family with one or more fallback font families. The default value is the font determined by the MessageFontFamily metric.

When multiple families are specified, the second and subsequent font families serve as fallback families to be used in cases where the primary font family is unavailable or not applicable.

This property specifies a preference only. If the specified font family is not available, the FlowDocument will silently fall back to the font determined by the MessageFontFamily metric.

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

<Paragraph
  FontFamily="Century Gothic, Courier New"  
  FontSize="16"
  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 this example renders.

Screenshot: Text with text properties set

The following example shows how to set the FontFamily 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 points 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;

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2015 Microsoft