Поделиться через


TextBlock.FontSize Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets the font size for the text content in this element.

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

Syntax

'Declaration
Public Property FontSize As Double
public double FontSize { get; set; }
<TextBlock FontSize="double" .../>

Property Value

Type: System.Double
A non-negative value that specifies the font size, measured in pixels. The default is 11.

Remarks

Dependency property identifier field: FontSizeProperty

FontSize settings for Run child elements override on the containing TextBlock.

For best results, specify integer values for FontSize, even though the property technically accepts floating-point values.

WPF Compatibility

In Windows Presentation Foundation (WPF), the XAML values for FontSize can include a unit qualifier such as "pt" or "px". However, these unit qualifiers are not supported in Silverlight. You can specify only a numeric value, which is always interpreted as pixels. If you are importing XAML UI definitions from WPF, you might need to modify the FontSize attribute values to remove the unit qualifiers, or convert the units.

Examples

The following XAML example shows how to use the FontSize property to define several text strings that are formatted differently.

<TextBlock
  FontFamily="Arial" Width="400" Text="Sample text formatting runs">
  <LineBreak/>
  <Run Foreground="Maroon" FontFamily="Courier New" 
     FontSize="24">Courier New 24</Run>
  <LineBreak/>
  <Run Foreground="Teal" FontFamily="Times New Roman" 
     FontSize="18" FontStyle="Italic">Times New Roman Italic 18</Run>
  <LineBreak/>
  <Run Foreground="SteelBlue" FontFamily="Verdana" FontSize="14" 
     FontWeight="Bold">Verdana Bold 14</Run>
</TextBlock>

The following illustration shows how the text from the previous example is rendered.

A TextBlock that is rendering different font sizes

Sample of text formatting runs.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.