TextBlock.TextAlignment プロパティ

定義

テキスト コンテンツの水平方向の配置を示す値を取得または設定します。Gets or sets a value that indicates the horizontal alignment of text content.

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

プロパティ値

目的の配置を指定する、いずれかの TextAlignment 値。One of the TextAlignment values that specifies the desired alignment. 既定値は、Left です。The default is Left.

次の例は、TextBlock 要素の TextAlignment 属性を設定する方法を示しています。The following example shows how to set the TextAlignment attribute of a TextBlock element.

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

次の例は、TextAlignment プロパティをプログラムで設定する方法を示しています。The following example shows how to set the TextAlignment property programmatically.

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

注釈

この依存関係プロパティには、プロパティの使用法も添付されています。This dependency property also has an attached property usage. XAMLXAMLでは、オブジェクトは <object TextBlock.TextAlignment="value".../>になります。ここで、 objectTextBlock内に含まれるオブジェクト要素 (通常はフロー要素) で、 valueTextAlignment 列挙体の文字列値です。In XAMLXAML, the usage is <object TextBlock.TextAlignment="value".../>, where object is an object element (typically a flow element) contained within a TextBlock, and value is a string value of the TextAlignment enumeration. コードでは、添付プロパティの使用は GetTextAlignmentSetTextAlignmentでサポートされています。In code, the attached property usage is supported by GetTextAlignment and SetTextAlignment. 添付プロパティの使用は一般的ではありません。The attached property usage is not common.

依存プロパティ情報Dependency Property Information

識別子フィールドIdentifier field TextAlignmentProperty
メタデータプロパティが true に設定されるMetadata properties set to true AffectsMeasureAffectsRenderInheritsAffectsMeasure, AffectsRender, Inherits

適用対象

こちらもご覧ください