TextBlock.TextAlignment Propriété

Définition

Obtient ou définit une valeur qui indique l’alignement horizontal du contenu textuel.

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

Valeur de propriété

TextAlignment

Une des valeurs TextAlignment qui spécifie l’alignement souhaité. La valeur par défaut est Left.

Exemples

L’exemple suivant montre comment définir l’attribut TextAlignment d’un TextBlock élément.

<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 TextAlignment propriété par programmation.

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

Remarques

Cette propriété de dépendance a également une utilisation de propriété jointe. En XAML, l’utilisation est <object TextBlock.TextAlignment="value".../>, où l’objet est un élément d’objet (généralement un élément de flux) contenu dans un TextBlock, et la valeur est une valeur de chaîne de l’énumération TextAlignment . Dans le code, l’utilisation de la propriété jointe est prise en charge par GetTextAlignment et SetTextAlignment. L’utilisation des propriétés jointes n’est pas courante.

Informations sur les propriétés de dépendance

Champ d’identificateur TextAlignmentProperty
Propriétés de métadonnées définies sur true AffectsMeasure, AffectsRender, Inherits

S’applique à

Voir aussi