TextBlock.FontWeight Propiedad

Definición

Obtiene o establece el espesor de la fuente de nivel superior para el 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

Valor de propiedad

FontWeight

Miembro de la clase FontWeights que especifica el espesor de la fuente deseado. El valor predeterminado viene determinado por el valor de MessageFontWeight.

Ejemplos

En el ejemplo siguiente se muestra cómo establecer el FontWeight atributo de un TextBlock elemento .

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

En el ejemplo siguiente se muestra cómo establecer la FontWeight propiedad mediante programación.

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

Comentarios

Cualquier FontWeight configuración de los elementos secundarios invalida esta configuración de nivel superior.

Para obtener una lista de valores válidos de pesos de fuente, vea la FontWeights clase .

Esta propiedad de dependencia también tiene un uso de propiedad adjunta. En XAML, el uso es <object TextBlock.FontWeight="value".../>, donde object es un elemento de objeto (normalmente un elemento flow) contenido en , TextBlocky value es uno de los valores de formato de cadena de una propiedad de la FontWeights clase . En el código, el uso de la propiedad adjunta es compatible con GetFontWeight y SetFontWeight. El uso de la propiedad adjunta no es común, ya que la mayoría de los elementos que se pueden contener en una TextBlock compatibilidad con una propiedad análoga no adjunta FontWeight , que usa TextBlock para la representación.

Información sobre propiedades de dependencia

Campo identificador FontWeightProperty
Propiedades de metadatos establecidas en true AffectsMeasure, AffectsRender, Inherits

Se aplica a