共用方式為


HOW TO:建立多行 TextBox 控制項

本範例示範如何使用Extensible Application Markup Language (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>

請參閱

參考

TextWrapping

概念

TextBox 概觀

RichTextBox 概觀