Uredi

Deli z drugimi prek


TextElement.FontFamily Property

Definition

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

public:
 property System::Windows::Media::FontFamily ^ FontFamily { System::Windows::Media::FontFamily ^ get(); void set(System::Windows::Media::FontFamily ^ value); };
[System.Windows.Localizability(System.Windows.LocalizationCategory.Font, Modifiability=System.Windows.Modifiability.Unmodifiable)]
public System.Windows.Media.FontFamily FontFamily { get; set; }
[<System.Windows.Localizability(System.Windows.LocalizationCategory.Font, Modifiability=System.Windows.Modifiability.Unmodifiable)>]
member this.FontFamily : System.Windows.Media.FontFamily with get, set
Public Property FontFamily As FontFamily

Property Value

The preferred font family or a primary preferred font family with one or more fallback font families. The default is the font determined by the MessageFontFamily value.

Attributes

Examples

The following example shows how to set the FontFamily 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 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 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;
Dim run As 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.")
Dim par As New Paragraph(run)

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

Remarks

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 silently falls back to the font determined by the MessageFontFamily value.

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

XAML Attribute Usage

<object FontFamily="fontFamilyName"/>  
- or -  
<object FontFamily="fontFamilyNamesList"/>  
- or -  
<object FontFamily="fontFamilyFolderReference"/>  
- or -  
<object FontFamily="fontFamilyUriReference"/>  

XAML Values

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 white space 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".

Dependency Property Information

Identifier field FontFamilyProperty
Metadata properties set to true AffectsMeasure, AffectsRender, Inherits

Applies to