TextElement.FontSize 属性

定义

获取或设置元素内容的字体大小。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

属性值

Double

要使用的字体大小,以与设备无关的像素为单位,大于0.001 且小于或等于35791。The desired font size to use in device independent pixels, greater than 0.001 and less than or equal to 35791. 默认值取决于当前的系统设置和 MessageFontSize 值。The default depends on current system settings and depends on the MessageFontSize value.

属性

例外

FontSize 设置为大于 35791 或小于或等于 0.001 的值。FontSize is set to a value greater than 35791 or less than or equal to 0.001.

示例

下面的示例演示如何 FontSize 使用 Paragraph 作为示例元素来设置特性。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.

屏幕快照:具有文本属性集的文本Screenshot: Text with text properties set

下面的示例演示如何以 FontSize 编程方式设置属性。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. 在中 XAMLXAML ,用法为 <object TextElement.FontSize="value".../> ,其中 object 是对象元素, (通常是包含在中的 flow 元素) TextElement 是字符串格式值之一,如 XAML 值中所述。In XAMLXAML, 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. 在代码中,和方法支持附加的属性用法 GetFontSize SetFontSizeIn code, the attached property usage is supported by the GetFontSize and SetFontSize methods. 附加的属性用法并不常见,因为可以包含在中的大多数元素都 TextElement 支持类似的非附加 FontSize 属性,内容宿主使用该属性来呈现。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.

XAML 属性用法XAML Attribute Usage

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

XAML 值XAML Values

doubledouble
Double

大于 Double 或等于0.0 但小于的值的字符串表示形式 PositiveInfinityString 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.

qualifiedDoublequalifiedDouble
如上所述的 双精度 值,后跟以下单元说明符之一: pxincmptA double value as described above, followed by one of the following unit specifiers: px, in, cm, pt.

px (默认) 为 与设备无关的单位(每个单位 1/96 英寸)device-independent units (1/96th inch per unit)px (default) is 与设备无关的单位(每个单位 1/96 英寸)device-independent units (1/96th inch per unit)

in 为英寸;1in = = 96pxin is inches; 1in==96px

cm 为厘米;1cm = = (96/2.54) pxcm is centimeters; 1cm==(96/2.54) px

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

依赖项属性信息Dependency Property Information

标识符字段Identifier field FontSizeProperty
元数据属性设置为 trueMetadata properties set to true AffectsMeasure, AffectsRender, InheritsAffectsMeasure, AffectsRender, Inherits

适用于