Condividi tramite


TextBlock.FontFamily Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System.Windows.Controls
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property FontFamily As FontFamily
public FontFamily FontFamily { get; set; }
<TextBlock FontFamily="fontFamily" />
-or-
<TextBlock FontFamily="fontFamilyName[,fallbackFontFamilyName]" />
-or-
<TextBlock FontFamily="fontURI#fontFamily" />

XAML Values

  • fontFamily
    A single font family name, for example "Verdana".

  • fontFamilyName[,fallbackFontFamilyName]
    A primary font family choice then one or more fallback font family choices, for example "Arial Unicode MS, Arial". See Remarks.

  • fontURI#fontFamily
    Used for non-default fonts. Specifies the resource location in the assembly for a font file, and a font family within that font. For information on this usage, see FontFamily. For more information on relative URIs for accessing font resources, see Resource Files.

Property Value

Type: System.Windows.Media.FontFamily
A FontFamily object that specifies the preferred font family, or a primary preferred font family with one or more fallback font families. For information about defaults, see the FontFamily class topic.

Exceptions

Exception Condition
ArgumentNullException

FontFamily is nulla null reference (Nothing in Visual Basic).

Remarks

Dependency property identifier field: FontFamilyProperty

The default value is a FontFamily for "Portable User Interface", which represents a composite font that uses a number of fonts to implement the range of international languages that are supported by Silverlight. This includes Lucida Sans Unicode and Lucida Grande for many Western writing systems, and many more for East Asian writing systems.

For more information, see FontFamily. For a complete list of supported fonts, see Text and Fonts. For information on how to specify a non-default FontFamily, where you distribute a font file as an assembly resource, see FontFamily.

Any FontFamily settings on Run child elements override the settings on the containing TextBlock.

Fallbacks for Fonts, as Specified in XAML

When multiple families are specified, the second and subsequent font families serve as fallback families to use if the primary font family is unavailable or not applicable. To specify multiple font families, use the following syntax:

fontFamilyName[,fallbackFontFamilyName]

In this syntax, fontFamilyName specifies the primary font, and fallbackFontFamilyName specifies an optional fallback. More than one fallback can be specified. Use commas to separate each font family string. To avoid ambiguity, if a font family contains a comma (",") in the name, each single comma in a font family reference must be replaced with a double comma (",,").

This property specifies a preference only. If the specified font family is not available, the TextBlock falls back silently to the "Portable User Interface" composite font.

NoteNote:

Most font files are licensed rather than sold, and licenses that govern the use of fonts vary from vendor to vendor. It is your responsibility to make sure that you have the required license rights for any font that you embed in a document or application, or that you otherwise redistribute.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.