TextBox.TextAlignment Property

Gets or sets a value indicating the horizontal alignment of the contents of the TextBox.

Namespace: System.Windows.Controls
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

property TextAlignment TextAlignment {
	TextAlignment get ();
	void set (TextAlignment value);
/** @property */
public TextAlignment get_TextAlignment ()

/** @property */
public void set_TextAlignment (TextAlignment value)

public function get TextAlignment () : TextAlignment

public function set TextAlignment (value : TextAlignment)

<object TextAlignment="TextAlignment" .../>

Property Value

A member of the TextAlignment enumeration specifying the horizontal alignment of the contents of the TextBox. Getting this property will return the current alignment. Setting this property will adjust the contents of the TextBox to reflect specified alignment. The default value is Left.

This property has a higher precedence then HorizontalContentAlignment.

The following example shows how to create a TextBox with a TextAlignment of Center.

<Page  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      Text="Initial text in TextBox" 
      MaxLines="5" />

StackPanel myStackPanel = new StackPanel();

//Create TextBox
TextBox myTextBox = new TextBox();
myTextBox.Width = 200;

// Put some initial text in the TextBox.
myTextBox.Text = "Initial text in TextBox";

// Set the maximum characters a user can manually type
// into the TextBox.
myTextBox.MaxLength = 500;
myTextBox.MinLines = 1;

// Set the maximum number of lines the TextBox will expand to 
// accomidate text. Note: This does not constrain the amount of 
// text that can be typed. To do that, use the MaxLength property.
myTextBox.MaxLines = 5;

// The text typed into the box is aligned in the center.
myTextBox.TextAlignment = TextAlignment.Center;

// When the text reaches the edge of the box, go to the next line.
myTextBox.TextWrapping = TextWrapping.Wrap;

this.Content = myStackPanel;

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions