Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TextBlock.FontSize Property

 

Gets or sets the top-level font size for the TextBlock.

Namespace:   System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)

<TypeConverterAttribute(GetType(FontSizeConverter))>
<LocalizabilityAttribute(LocalizationCategory.None)>
Public Property FontSize As Double

Property Value

Type: System.Double

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

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.

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

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

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.

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

.NET Framework
Available since 3.0
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show:
© 2017 Microsoft