TextBlock.FontStyle プロパティ

定義

TextBlock に対して、最上位レベルのフォント スタイルを取得または設定します。

public:
 property System::Windows::FontStyle FontStyle { System::Windows::FontStyle get(); void set(System::Windows::FontStyle value); };
public System.Windows.FontStyle FontStyle { get; set; }
member this.FontStyle : System.Windows.FontStyle with get, set
Public Property FontStyle As FontStyle

プロパティ値

適切なフォント スタイルを指定する FontStyles クラスのメンバー。 既定値は MessageFontStyle 値で決定されます。

次の例は、 要素の 属性を設定する FontStyle 方法を 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>

次の例では、FontStyle プロパティをプログラムで設定する方法を示しています。

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

注釈

FontStyle子要素のすべての設定は、この最上位の設定をオーバーライドします。

この依存関係プロパティには、添付プロパティの使用法もあります。 XAML では、使用法は です <object TextBlock.FontStyle="value".../>ここで、object は 内 TextBlockに含まれるオブジェクト要素 (通常はフロー要素) であり、 は クラス内 FontStyles の文字列形式のプロパティ名の 1 つです。 コードでは、添付プロパティの使用法は と SetFontStyleGetFontStyleサポートされています。 添付プロパティの使用方法は一般的ではありません。これは、 に含めることができるほとんどの要素が、レンダリングに TextBlock 使用する類似の非アタッチ FontStyle プロパティを TextBlock サポートするためです。

依存プロパティ情報

識別子フィールド FontStyleProperty
に設定されたメタデータ プロパティ true AffectsMeasure, AffectsRender, Inherits

適用対象