TextBlock.FontSize Propiedad

Definición

Obtiene o establece el tamaño de fuente de nivel superior para el TextBlock.

public:
 property double FontSize { double get(); void set(double value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.FontSizeConverter))]
[System.Windows.Localizability(System.Windows.LocalizationCategory.None)]
public double FontSize { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.FontSizeConverter))>]
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None)>]
member this.FontSize : double with get, set
Public Property FontSize As Double

Valor de propiedad

Tamaño de fuente deseado para usarlo en píxeles independientes del dispositivo. El valor predeterminado viene determinado por el valor de MessageFontSize.

Atributos

Ejemplos

En el ejemplo siguiente se muestra cómo establecer el FontSize 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 propiedad FontSize 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 FontSize configuración de los elementos secundarios invalida esta configuración de nivel superior.

Esta propiedad de dependencia también tiene un uso de propiedad adjunta. En XAML, el uso es <object TextBlock.FontSize="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, como se explica en Valores XAML. En el código, el uso de la propiedad adjunta es compatible con GetFontSize y SetFontSize. 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 FontSize , que usa TextBlock para la representación.

Uso de atributos XAML

<object FontSize="double"/>  
- or -  
<object FontSize="qualifiedDouble"/>  

Valores XAML

double
Double

Representación de cadena de un Double valor igual o mayor que 0,0, pero menor que PositiveInfinity. Un valor no completo se mide en píxeles independientes del dispositivo. Las cadenas no necesitan incluir explícitamente puntos decimales.

qualifiedDouble
Valor doble como se ha descrito anteriormente, seguido de uno de los siguientes especificadores de unidad: px, in, cm, pt.

px (valor predeterminado) es unidades independientes del dispositivo (1/96 pulgadas por unidad)

in es pulgadas; 1in==96px

cm es centímetros; 1cm==(96/2.54) px

pt es puntos; 1pt==(96/72) px

Información sobre propiedades de dependencia

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

Se aplica a