Share via


TextBlock.TextAlignment Proprietà

Definizione

Ottiene o imposta un valore che indica l'allineamento orizzontale del contenuto di testo.

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

Valore della proprietà

TextAlignment

Uno dei valori di TextAlignment che specifica l'allineamento desiderato. Il valore predefinito è Left.

Esempio

Nell'esempio seguente viene illustrato come impostare l'attributo TextAlignment di un TextBlock elemento.

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

Nell'esempio seguente viene illustrato come impostare la TextAlignment proprietà a livello di codice.

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

Commenti

Questa proprietà di dipendenza ha anche un utilizzo di proprietà collegato. In XAML l'utilizzo è , dove l'oggetto è <object TextBlock.TextAlignment="value".../>un elemento oggetto (in genere un elemento flow) contenuto in un TextBlockoggetto e il valore è un valore stringa dell'enumerazioneTextAlignment. Nel codice l'utilizzo della proprietà associata è supportato da GetTextAlignment e SetTextAlignment. L'utilizzo delle proprietà associate non è comune.

Informazioni proprietà di dipendenza

Campo Identificatore TextAlignmentProperty
Proprietà dei metadati impostate su true AffectsMeasure, AffectsRender, Inherits

Si applica a

Vedi anche