跳到正文
浏览文档

Textarea

位于 Input 边框内的多行输入,即启用了 AcceptsReturn 的 TextBox。

示例可交互
Textarea — Avalonia UIKit
Live demo unavailable
<TextBox AcceptsReturn="True" MinLines="3" MaxLines="3" PlaceholderText="Write a message"
         Width="280" HorizontalAlignment="Left" />

用法

TextBox AcceptsReturn="True" 就是 textarea。它没有固定高度:用 MinLines 与 MaxLines 给出行数,或设置 Height。主题会折行(TextWrapping="Wrap"),把文本对齐到顶部,并在滚动区域内而不是边框内加内边距,因此浮层滚动条沿整个内框延伸。边框、占位符、焦点环、禁用外观与右键菜单都来自 Input。尺寸:xsmall、small、large(默认为 medium)。

uikit:Inputs.TabSize(通常为 2)让 Tab 键缩进:在光标处,或对每个选中的行。Shift+Tab 减少光标处或选中行的缩进,Cmd+] 与 Cmd+[(Windows 与 Linux 上为 Ctrl+] 与 Ctrl+[)缩进与减少缩进。uikit:Inputs.HardTabs="True" 用制表符而不是空格缩进。只读的 textarea,或没有设置 TabSize 的 textarea,会把 Tab 留给焦点移动。

示例

MinLines="2" MaxLines="5":输入框随文本从两行增长到五行,然后滚动。

自动增高可交互
Live demo unavailable
<StackPanel Spacing="12" Width="280" HorizontalAlignment="Left">
  <TextBox AcceptsReturn="True" MinLines="2" MaxLines="5" Text="One" />
  <TextBox AcceptsReturn="True" MinLines="2" MaxLines="5" Text="One&#10;Two&#10;Three&#10;Four" />
</StackPanel>

四种尺寸,每个都是两行高。

尺寸可交互
Live demo unavailable
<StackPanel Spacing="12" Width="280" HorizontalAlignment="Left">
  <TextBox Classes="xsmall" AcceptsReturn="True" MinLines="2" MaxLines="2" PlaceholderText="Extra small" />
  <TextBox Classes="small" AcceptsReturn="True" MinLines="2" MaxLines="2" PlaceholderText="Small" />
  <TextBox AcceptsReturn="True" MinLines="2" MaxLines="2" PlaceholderText="Medium" />
  <TextBox Classes="large" AcceptsReturn="True" MinLines="2" MaxLines="2" PlaceholderText="Large" />
</StackPanel>

只读与禁用的 textarea。

状态可交互
Live demo unavailable
<StackPanel Spacing="12" Width="280" HorizontalAlignment="Left">
  <TextBox AcceptsReturn="True" MinLines="3" MaxLines="3" Text="Read only&#10;notes" IsReadOnly="True" />
  <TextBox AcceptsReturn="True" MinLines="3" MaxLines="3" Text="Disabled" IsEnabled="False" />
</StackPanel>

选中多行并按下 Tab 或 Shift+Tab。

缩进可交互
Live demo unavailable
<TextBox AcceptsReturn="True" MinLines="4" MaxLines="4" Width="320" HorizontalAlignment="Left"
         uikit:Inputs.TabSize="2"
         Text="Select these lines&#10;and press Tab to indent them,&#10;Shift+Tab to outdent." />