TextBlock.TextAlignment Property

Definition

Obtient ou définit une valeur qui indique l’alignement horizontal du contenu textuel.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

Property Value

TextAlignment

Une des valeurs TextAlignment qui spécifie l’alignement souhaité.One of the TextAlignment values that specifies the desired alignment. Par défaut, il s’agit de Left.The default is Left.

Examples

L’exemple suivant montre comment définir l’attribut TextAlignment d’un élément TextBlock.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>

L’exemple suivant montre comment définir la propriété TextAlignment par programmation.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

Remarks

Cette propriété de dépendance a également une utilisation de propriété jointe.This dependency property also has an attached property usage. Dans XAMLXAML, l’utilisation est <object TextBlock.TextAlignment="value".../>, où Object est un élément Object (généralement un élément Flow) contenu dans un TextBlock, et value est une valeur de chaîne de l’énumération TextAlignment.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. Dans le code, l’utilisation de la propriété jointe est prise en charge par GetTextAlignment et SetTextAlignment.In code, the attached property usage is supported by GetTextAlignment and SetTextAlignment. L’utilisation de la propriété jointe n’est pas courante.The attached property usage is not common.

Informations sur les propriétés de dépendanceDependency Property Information

Champ d’identificateurIdentifier field TextAlignmentProperty
Propriétés de métadonnées définies sur trueMetadata properties set to true AffectsMeasure, AffectsRender, InheritsAffectsMeasure, AffectsRender, Inherits

Applies to

See also