Partilhar via


TextBlock.FontWeight Propriedade

Definição

Obtém ou define o peso da fonte de nível superior para o 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 da propriedade

Um membro da FontWeights classe que especifica o peso da fonte desejado. O padrão é determinado pelo MessageFontWeight valor.

Exemplos

O exemplo a seguir mostra como definir o FontWeight atributo de um 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>

O exemplo a seguir mostra como definir a propriedade FontWeight programaticamente.

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

Comentários

Todas as FontWeight configurações em elementos filho substituem essa configuração de nível superior.

Para obter uma lista de valores válidos de pesos de fonte, consulte a FontWeights classe.

Essa propriedade de dependência também tem um uso de propriedade anexada. No XAML, o uso é <object TextBlock.FontWeight="value".../>, em que o objeto é um elemento de objeto (normalmente um elemento de fluxo) contido em um TextBlock, e o valor é um dos valores de formato de cadeia de caracteres de uma propriedade da FontWeights classe. No código, o uso da propriedade anexada tem suporte GetFontWeight e SetFontWeight. O uso de propriedade anexada não é comum, pois a maioria dos elementos que podem ser contidos em uma TextBlock propriedade nãonattached FontWeight análoga, que usa TextBlock para renderização.

Informações da propriedade Dependency

Item Valor
Campo identificador FontWeightProperty
Propriedades de metadados definidas como true AffectsMeasure, , AffectsRenderInherits

Aplica-se a