TextElement.FontStyle 属性

定义

获取或设置元素内容的字体样式。Gets or sets the font style for the content of the element.

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

所需的字体样式。The desired font style. 默认值由 MessageFontStyle 值确定。The default is determined by the MessageFontStyle value.

示例

下面的示例演示如何 FontStyle 使用 Paragraph 作为示例元素来设置特性。The following example shows how to set the FontStyle 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

下面的示例演示如何以 FontStyle 编程方式设置属性。The following example shows how to set the FontStyle 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

注解

此依赖属性还具有附加的属性用法。This dependency property also has an attached property usage. 在 XAML 中,使用是 <object TextElement.FontStyle="value".../> ,其中 object 是对象元素, (通常是包含在中的 flow 元素) TextElement 是类中的字符串格式属性名称之一 FontStylesIn XAML, the usage is <object TextElement.FontStyle="value".../>, where object is an object element (typically a flow element) contained within a TextElement, and value is one of the string-format property names in the FontStyles class. 在代码中,和方法支持附加的属性用法 GetFontStyle SetFontStyleIn code, the attached property usage is supported by the GetFontStyle and SetFontStyle methods. 附加的属性用法并不常见,因为可以包含在中的大多数元素都 TextElement 支持类似的非附加 FontStyle 属性,内容宿主使用该属性来呈现。The attached property usage is not common, because most elements that can be contained in a TextElement support an analogous nonattached FontStyle property, which the content host uses for rendering.

依赖项属性信息Dependency Property Information

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

适用于