TextBlock.FontWeight 屬性

定義

取得或設定 TextBlock 的最上層字型粗細。

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

屬性值

FontWeights 類別成員,指定所需字型粗細。 預設值是由 MessageFontWeight 值決定。

範例

下列範例示範如何設定 FontWeight 專案的 屬性 TextBlock

<TextBlock 
  Name="textBlock"
  
  Background="AntiqueWhite" 
  Foreground="Navy" 
  
  FontFamily="Century Gothic"
  FontSize="12"
  FontStretch="UltraExpanded"
  FontStyle="Italic"
  FontWeight="UltraBold"
  
  LineHeight="Auto"
  Padding="5,10,5,10"
  TextAlignment="Center"
  TextWrapping="Wrap"
  
  Typography.NumeralStyle="OldStyle"
  Typography.SlashedZero="True"
>
  <Run Background="LightGreen">Text run 1.</Run>
  <LineBreak/><Run Background="LightBlue">Text run 2.</Run>
  <LineBreak/><Run Background="LightYellow">Text run 3.</Run>
</TextBlock>

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

TextBlock textBlock = new TextBlock(new Run("A bit of text content..."));

textBlock.Background              = Brushes.AntiqueWhite;
textBlock.Foreground              = Brushes.Navy;

textBlock.FontFamily              = new FontFamily("Century Gothic");
textBlock.FontSize                = 12;
textBlock.FontStretch             = FontStretches.UltraExpanded;
textBlock.FontStyle               = FontStyles.Italic;
textBlock.FontWeight              = FontWeights.UltraBold;

textBlock.LineHeight              = Double.NaN;
textBlock.Padding                 = new Thickness(5, 10, 5, 10);
textBlock.TextAlignment           = TextAlignment.Center;
textBlock.TextWrapping            = TextWrapping.Wrap;

textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle;
textBlock.Typography.SlashedZero  = true;
Dim textBlock As New TextBlock(New Run("A bit of text content..."))

textBlock.Background = Brushes.AntiqueWhite
textBlock.Foreground = Brushes.Navy

textBlock.FontFamily = New FontFamily("Century Gothic")
textBlock.FontSize = 12
textBlock.FontStretch = FontStretches.UltraExpanded
textBlock.FontStyle = FontStyles.Italic
textBlock.FontWeight = FontWeights.UltraBold

textBlock.LineHeight = Double.NaN
textBlock.Padding = New Thickness(5, 10, 5, 10)
textBlock.TextAlignment = TextAlignment.Center
textBlock.TextWrapping = TextWrapping.Wrap

textBlock.Typography.NumeralStyle = FontNumeralStyle.OldStyle
textBlock.Typography.SlashedZero = True

備註

子項目上的任何 FontWeight 設定會覆寫此最上層設定。

如需字型粗細的有效值清單,請參閱 FontWeights 類別。

這個相依性屬性也有附加的屬性使用方式。 在 XAML 中,用法是 <object TextBlock.FontWeight="value".../> ,其中 object 是物件 專案 (通常是包含在 內的 TextBlock 流程專案) , 而 值 是 類別屬性的 FontWeights 其中一個字串格式值。 在程式碼中,和 SetFontWeight 支援 GetFontWeight 附加屬性使用方式。 附加屬性使用方式並不常見,因為大部分可以包含在 TextBlock 中的元素都支援類似的非附加 FontWeight 屬性,以供 TextBlock 轉譯使用。

相依性屬性資訊

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

適用於