TextElement.FontStyle 屬性

定義

取得或設定項目內容的字型樣式。

public:
 property System::Windows::FontStyle FontStyle { System::Windows::FontStyle get(); void set(System::Windows::FontStyle value); };
public System.Windows.FontStyle FontStyle { get; set; }
member this.FontStyle : System.Windows.FontStyle with get, set
Public Property FontStyle As FontStyle

屬性值

FontStyle

所需的字型樣式。 預設值是由 MessageFontStyle 值決定。

範例

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

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

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

螢幕擷取畫面:已設定文字屬性的文字

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

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

備註

此相依性屬性也有附加屬性使用方式。 在 XAML 中,使用方式是 <object TextElement.FontStyle="value".../> ,其中 object 是物件 專案, (通常是包含在 中的 TextElement 流程專案) ,而 value 是 類別中的 FontStyles 其中一個字串格式屬性名稱。 在程式碼中,和 SetFontStyle 方法支援 GetFontStyle 附加屬性使用方式。 附加屬性使用方式並不常見,因為大部分可以包含在 中的 TextElement 元素都支援類似非附加 FontStyle 屬性,內容主機會用來轉譯。

相依性屬性資訊

識別碼欄位 FontStyleProperty
中繼資料屬性設定為 true AffectsMeasureAffectsRenderInherits

適用於