Επεξεργασία

Κοινή χρήση μέσω


TextBlock.FontSize Property

Definition

Gets or sets the top-level font size for the 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

Property Value

The desired font size to use in device independent pixels). The default is determined by the MessageFontSize value.

Attributes

Examples

The following example shows how to set the FontSize attribute of a TextBlock element.

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

The following example shows how to set the FontSize property programmatically.

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

Remarks

Any FontSize settings on child elements override this top-level setting.

This dependency property also has an attached property usage. In XAML, the usage is <object TextBlock.FontSize="value".../>, where object is an object element (typically a flow element) contained within a TextBlock, and value is one of the string-format values as explained in XAML Values. In code, the attached property usage is supported by GetFontSize and SetFontSize. The attached property usage is not common, because most elements that can be contained in a TextBlock support an analogous nonattached FontSize property, which the TextBlock uses for rendering.

XAML Attribute Usage

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

XAML Values

double
Double

String representation of a Double value equal to or greater than 0.0 but smaller than PositiveInfinity. An unqualified value is measured in device independent pixels. Strings need not explicitly include decimal points.

qualifiedDouble
A double value as described above, followed by one of the following unit specifiers: px, in, cm, pt.

px (default) is device-independent units (1/96th inch per unit)

in is inches; 1in==96px

cm is centimeters; 1cm==(96/2.54) px

pt is points; 1pt==(96/72) px

Dependency Property Information

Identifier field FontSizeProperty
Metadata properties set to true AffectsMeasure, AffectsRender, Inherits

Applies to