共用方式為


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

例外狀況

範例

下列範例示範如何建立 TextBox 值為 5 的 MaxLines

<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

適用於

另請參閱