TextElement.FontSize Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the font size for the content of the element.
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
The desired font size to use in device independent pixels, greater than 0.001 and less than or equal to 35791. The default depends on current system settings and depends on the MessageFontSize value.
- Attributes
FontSize is set to a value greater than 35791 or less than or equal to 0.001.
The following example shows how to set the FontSize attribute, using Paragraph as the example element.
<Paragraph
FontFamily="Century Gothic, Courier New"
FontSize="16pt"
FontStretch="UltraExpanded"
FontStyle="Italic"
FontWeight="DemiBold"
>
<Run>
This text will use the Century Gothic font (if available), with fallback to Courier New. It
will render with a font size of 16 points in ultra-expanded demi-bold italic.
</Run>
</Paragraph>
The following figure shows how the preceding example renders.
The following example shows how to set the FontSize property programmatically.
Run run = new Run(
"This text will use the Century Gothic font (if available), with fallback to Courier New."
+ "It will render with a font size of 16 pixels in ultra-expanded demi-bold italic.");
Paragraph par = new Paragraph(run);
par.FontFamily = new FontFamily("Century Gothic, Courier New");
par.FontSize = 16;
par.FontStretch = FontStretches.UltraExpanded;
par.FontStyle = FontStyles.Italic;
par.FontWeight = FontWeights.DemiBold;
Dim run As New Run("This text will use the Century Gothic font (if available), with fallback to Courier New." & "It will render with a font size of 16 pixels in ultra-expanded demi-bold italic.")
Dim par As New Paragraph(run)
With par
.FontFamily = New FontFamily("Century Gothic, Courier New")
.FontSize = 16
.FontStretch = FontStretches.UltraExpanded
.FontStyle = FontStyles.Italic
.FontWeight = FontWeights.DemiBold
End With
This dependency property also has an attached property usage. In XAML, the usage is <object TextElement.FontSize="value".../>
, where object is an object element (typically a flow element) contained within a TextElement, and value is one of the string-format values as explained in XAML Values. In code, the attached property usage is supported by the GetFontSize and SetFontSize methods. The attached property usage is not common, because most elements that can be contained in a TextElement support an analogous nonattached FontSize
property, which the content host 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
Item | Value |
---|---|
Identifier field | FontSizeProperty |
Metadata properties set to true |
AffectsMeasure, AffectsRender, Inherits |
Product | Versions |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: