TextElement.FontFamily 屬性

定義

取得或設定項目內容慣用的最上層字型家族。

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

屬性值

慣用字型系列或具有一或多個後援字型系列的主要慣用字型系列。 預設為由 MessageFontFamily 值決定的字型。

屬性

範例

下列範例示範如何使用 做為範例專案來 Paragraph 設定 FontFamily 屬性。

<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>

下圖顯示上述範例的呈現方式。

螢幕擷取畫面:文字屬性集的文字

下列範例示範如何以程式設計方式設定 FontFamily 屬性。

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

備註

指定多個系列時,第二個和後續字型系列可作為後援系列,以供主要字型系列無法使用或不適用時使用。

此屬性僅指定喜好設定。 如果指定的字型系列無法使用,則會 FlowDocument 以無訊息方式回復為值所決定的字型 MessageFontFamily

這個相依性屬性也有附加的屬性使用方式。 在 XAML 中,使用方式是 <object TextElement.FontFamily="value".../> ,其中 object 是物件專案 (通常是包含在 內的 TextBlock 流程專案) ,而 是 XAML 值中所述的其中一個字串格式值。 在程式碼中,和 SetFontFamily 方法支援 GetFontFamily 附加屬性使用方式。 附加屬性使用方式並不常見,因為大部分可以包含在 支援類似非附加 FontFamily 屬性的專案 TextElement ,內容主機會用來轉譯。

XAML Attribute Usage

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

XAML 值

fontFamilyName
指定字型系列名稱的字串。 例如,"Arial""Century Gothic"

fontFamilyNamesList
指定多個字型系列名稱的字串,每個名稱會以逗號分隔, (忽略在逗號之後的任何空白字元) 。 指定的第一個字型系列做為主要字型系列;後續字型系列可作為後援系列,用於主要字型系列無法使用或不適用的情況。 例如, "Arial, Century Gothic" 將 Arial 指定為主要字型系列,而 Century 為後援字型系列。

fontFamilyFolderReference
指定包含字型的資料夾以及字型系列名稱的字串。 資料夾和字型系列名稱是以 # 字元分隔。 資料夾參考可能是絕對或相對的。 例如: "Custom Fonts\#My Custom Font"

fontFamilyUriReference
字串,指定字型的統一資源識別項 (URI) ,以及字型系列名稱。 URI 和字型系列名稱是以 # 字元分隔。 例如: "http://MyFontServer/Fonts/#My Custom Font"

相依性屬性資訊

識別碼欄位 FontFamilyProperty
設定為 的中繼資料屬性 true AffectsMeasure, AffectsRender, Inherits

適用於