TextElement.FontFamily 属性

定义

获取或设置元素内容的首选顶级字体系列。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

属性值

FontFamily

首选的字体系列,或者具有一个或多个备用字体系列的主要首选字体系列。The preferred font family or a primary preferred font family with one or more fallback font families. 默认值为由 MessageFontFamily 值确定的字体。The default is the font determined by the MessageFontFamily value.

属性

示例

下面的示例演示如何 FontFamily 使用 Paragraph 作为示例元素来设置特性。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

下面的示例演示如何以 FontFamily 编程方式设置属性。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

注解

指定多个系列后,第二个和后续的字体系列作为备用系列,在主要字体系列不可用或不适用的情况下使用。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. 如果指定的字体系列不可用,则会 FlowDocument 以静默方式回退到由值确定的字体 MessageFontFamilyIf 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. 在中 XAMLXAML ,用法为 <object TextElement.FontFamily="value".../> ,其中 object 是对象元素, (通常是包含在中的 flow 元素) TextBlock 是字符串格式值之一,如 XAML 值中所述。In XAMLXAML, 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. 在代码中,和方法支持附加的属性用法 GetFontFamily SetFontFamilyIn code, the attached property usage is supported by the GetFontFamily and SetFontFamily methods. 附加的属性用法并不常见,因为可以包含在中的大多数元素都 TextElement 支持类似的非附加 FontFamily 属性,内容宿主使用该属性来呈现。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 属性用法XAML Attribute Usage

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

XAML 值XAML Values

fontFamilyNamefontFamilyName
指定字体系列名称的字符串。A string specifying a font family name. 例如,"Arial""Century Gothic"For example, "Arial" or "Century Gothic".

fontFamilyNamesListfontFamilyNamesList
指定多个字体系列名称的字符串(每个名称之间用逗号分隔) () 中忽略逗号之后的任何空白。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. 例如,将 "Arial, Century Gothic" 宋体指定为主要字体系列,并将世纪宋指定为备用字体系列。For example, "Arial, Century Gothic" specifies Arial as the primary font family, with Century Gothic as the fallback font family.

fontFamilyFolderReferencefontFamilyFolderReference
指定包含字体的文件夹以及字体系列名称的字符串。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. 例如 "Custom Fonts\#My Custom Font"For example, "Custom Fonts\#My Custom Font".

fontFamilyUriReferencefontFamilyUriReference
一个字符串,指定 (URI) 的统一资源标识符,以及字体系列名称。A string specifying a uniform resource identifier (URI) for the font, along with a font family name. URI 和字体系列名称由 # 字符分隔。The URI and font family name are delimited by a # character. 例如 "http://MyFontServer/Fonts/#My Custom Font"For example, "http://MyFontServer/Fonts/#My Custom Font".

依赖项属性信息Dependency Property Information

标识符字段Identifier field FontFamilyProperty
元数据属性设置为 trueMetadata properties set to true AffectsMeasure, AffectsRender, InheritsAffectsMeasure, AffectsRender, Inherits

适用于