TextBox.MaxLines 属性

定义

获取或设置最大可见行数。

public:
 property int MaxLines { int get(); void set(int value); };
public int MaxLines { get; set; }
member this.MaxLines : int with get, set
Public Property MaxLines As Integer

属性值

最大可见行数。 默认值为 Int32.MaxValue

例外

示例

以下示例演示如何创建TextBoxMaxLines值为 5 的 。

<Page  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <StackPanel>
    <TextBox 
      Text="Initial text in TextBox" 
      Width="200" 
      TextAlignment="Center"
      TextWrapping="Wrap" 
      MaxLength="500"
      MinLines="1" 
      MaxLines="5" />
  </StackPanel>
</Page>
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;

myStackPanel.Children.Add(myTextBox);
this.Content = myStackPanel;
Dim myStackPanel As New StackPanel()

'Create TextBox
Dim myTextBox As 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

myStackPanel.Children.Add(myTextBox)
Me.Content = myStackPanel

注解

获取此属性将返回 的 MaxLines当前值。 如果可见行数超过 指定的 MaxLines限制,则设置此属性会使文本框调整大小。

此属性仅适用于可见行,不限制实际行数。 根据文本框的配置,文本框可能包含可通过滚动访问的其他不可见行。

Height如果在 上TextBox显式设置了 属性,则MaxLines忽略 和 MinLines 属性值。

依赖项属性信息

标识符字段 MaxLinesProperty
元数据属性设置为 true AffectsMeasure

适用于

另请参阅