TextBox.MaxLines TextBox.MaxLines TextBox.MaxLines TextBox.MaxLines Property

定义

获取或设置最大可见行数。Gets or sets the maximum number of visible lines.

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

属性值

最大可见行数。The maximum number of visible lines. 默认值为 MaxValueThe default is MaxValue.

异常

示例

下面的示例演示如何创建TextBox MaxLines值为5的。The following example shows how to create a TextBox with a MaxLines value of 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

注解

获取此属性将返回的当前值MaxLinesGetting this property returns the current value of MaxLines. 设置此属性将导致文本框在可见行数超出指定MaxLines的限制时调整大小。Setting this property causes the text box to resize if the number of visible lines exceeds the limit specified by MaxLines.

此属性仅适用于可见行, 不约束实际的行数。This property applies only to visible lines, and does not constrain the actual number of lines. 根据其配置, 文本框可能包含可通过滚动访问的其他不可见的行。Depending on its configuration, a text box may contain additional non-visible lines that are accessible by scrolling.

如果在MaxLines MinLines上显式设置了Height属性,则和属性值TextBox将被忽略。If the Height property is explicitly set on a TextBox, the MaxLines and MinLines property values are ignored.

依赖项属性信息Dependency Property Information

标识符字段Identifier field MaxLinesProperty
元数据属性设置为trueMetadata properties set to true AffectsMeasure

适用于

另请参阅