如何:创建多行文本框控件

此示例演示如何使用可扩展应用程序标记语言(XAML)定义 TextBox 将自动扩展以适应多行文本的控件。

示例:

TextWrapping属性设置为Wrap后,当文本到达TextBox控件的边缘时,会自动换行。如果有必要,TextBox控件会自动扩展以容纳新行的空间。

AcceptsReturn 属性设置为 true 会导致在按下 RETURN 键时插入新行,如有必要,再次自动展开 TextBox 要包含新行的空间。

VerticalScrollBarVisibility 属性将滚动条添加到 TextBox 以便滚动浏览 TextBox 的内容,如果 TextBox 的扩展超出了包含它的框架或窗口大小。

<TextBox
  Name="tbMultiLine"
  TextWrapping="Wrap"
  AcceptsReturn="True"
  VerticalScrollBarVisibility="Visible"
>
  This TextBox will allow the user to enter multiple lines of text.  When the RETURN key is pressed, 
  or when typed text reaches the edge of the text box, a new line is automatically inserted.
</TextBox>

另请参阅