TextBlock.FontSize 屬性

定義

取得或設定 TextBlock 的最上層字型大小。

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

屬性值

以與裝置無關的像素使用所要的字型大小。 預設值是由 MessageFontSize 值決定。

屬性

範例

下列範例示範如何設定 FontSize 專案的 屬性 TextBlock

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

下列範例示範如何以程式設計方式設定 FontSize 屬性。

TextBlock textBlock = 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;
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

備註

子項目上的任何 FontSize 設定會覆寫此最上層設定。

此相依性屬性也有附加屬性使用方式。 在 XAML 中,使用方式是 <object TextBlock.FontSize="value".../> ,其中 object 是物件 元素 (通常是流程專案) 包含在 內 TextBlock而 value 是其中一個字串格式值,如 XAML 值中所述。 在程式碼中,和 SetFontSize 支援 GetFontSize 附加屬性使用方式。 附加屬性使用方式並不常見,因為可以包含在 中的 TextBlock 大部分元素都支援用於轉譯 FontSizeTextBlock 類似非附加屬性。

XAML Attribute Usage

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

XAML 值

double
Double

值的字串表示 Double 等於或大於 0.0,但小於 PositiveInfinity 。 不合格的值是以裝置獨立圖元來測量。 字串不需要明確包含小數點。

qualifiedDouble
如上所述的 雙精度 浮點數,後面接著下列其中一個單位規範: px 、、 incmpt 、 。

px (預設) 是裝置獨立單位 (,每單位 1/96 英吋)

in 為英吋;1in==96px

cm 為公分;1cm== (96/2.54) px

pt 為點;1pt== (96/72) px

相依性屬性資訊

識別碼欄位 FontSizeProperty
設定為 的中繼資料屬性 true AffectsMeasure, AffectsRender, Inherits

適用於