TextElement.FontWeight 属性

定义

获取或设置元素内容的顶级字体粗细。

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

属性值

FontWeight

所需的字体粗细。 默认值由 MessageFontWeight 值确定。

示例

以下示例演示如何使用Paragraph示例元素设置FontWeight属性。

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

下图显示了上述示例的呈现方式。

屏幕快照:具有文本属性集的文本

下面的示例演示如何以编程方式设置 FontWeight 属性。

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.FontWeight="value".../>对象是对象 元素 (通常包含的流元素) TextElement 是枚举的字符串格式值 FontWeight 之一。 在代码中,附加属性用法由 GetFontWeightSetFontWeight 方法支持。 附加属性用法并不常见,因为大多数元素可以包含在支持类似的非附加FontWeight属性中TextElement,内容主机使用该属性进行呈现。

依赖项属性信息

标识符字段 FontWeightProperty
元数据属性设置为 true AffectsMeasureAffectsRenderInherits

适用于