Sdílet prostřednictvím


FontSize

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

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

<object FontSize="Double"  .../>
value = object.FontSize
object.FontSize = value

Property Value

Type: Double

A non-negative value that specifies the desired font size, in pixels.

This property is read/write. The default value is 14.666.

Remarks

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 must specify a numeric value only, which is always interpreted as pixels. If you are importing XAML user interface definitions from WPF, you might have to adjust the FontSize attribute values to strip the unit qualifiers, or convert the units.

The "Applies To" section of this topic lists LineBreak, because it does exist in the object model and you can get and set it. However, all LineBreak properties are ignored for rendering purposes. In particular, changing FontSize does not affect the height of the line break. Only the FontSize setting on the text runs has any effect. The line height for a LineBreak is influenced by the surrounding runs, but multiple line breaks in succession will use the default 14.66 pixel height.

Example

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

<!-- Display formatted text as Run objects within a TextBlock. -->
<Canvas
  xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation">

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

</Canvas>

Applies To

LineBreak

Run

PasswordBox (Silverlight 2)

TextBlock

TextBox (Silverlight 2)