TextBox.MaxLines Property

Gets or sets the maximum number of visible lines to size to.

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

public int MaxLines { get; set; }
/** @property */
public int get_MaxLines ()

/** @property */
public void set_MaxLines (int value)

public function get MaxLines () : int

public function set MaxLines (value : int)

<object MaxLines="int" .../>

Property Value

An integer indicating the maximum number of visible lines to size to. Getting this property returns the current value of MaxLines. Setting this property causes the TextBox to resize if the number of visible lines exceeds the limit specified by MaxLines. The default value is MaxValue.

Exception typeCondition


The value of MaxLines must be greater than or equal to the value of MinLines.

This property applies only to visible lines, and does not constrain the actual number of lines. Depending on its configuration, a TextBox may contain additional non-visible lines that are accessible by scrolling.

If Height is explicitly set on TextBox, MaxLines and MinLines property values are ignored.

The following example shows how to create a TextBox with a MaxLines of 5.

<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