信息
您所需的主题如下所示。但此主题未包含在此库中。

TextBox.AcceptsReturn 属性

2013/12/13

获取或设置一个值,该值确定文本框是否允许和显示换行符或回车符。

Namespace:  System.Windows.Controls
程序集:  System.Windows(位于 System.Windows.dll 中)
XMLNS for XAML: 未映射到 xmlns。

public bool AcceptsReturn { get; set; }
<TextBox AcceptsReturn="bool"/>

属性值

类型: System.Boolean
如果文本框允许换行符,则为 true;否则为 false。 默认值为 false

依赖项属性标识符字段: AcceptsReturnProperty.

如果您将 AcceptsReturn 属性更改为 true,则文本可能由于文本中包含换行符而以不同方式显示。

可以通过使用 AcceptsReturn 属性在 TextBox 控件中启用多行文本。 使用 HorizontalScrollBarVisibilityVerticalScrollBarVisibility 属性以启用水平滚动条或垂直滚动条。

下面的代码段演示您如何能够在 XAML 和代码中使用 AcceptsReturn 属性以创建带有滚动条的多行文本框控件。


<StackPanel>
    <TextBox Margin="20,20,0,0" Text="A text box that demonstrates TextWrapping, TextAlignment, MaxLength, and AcceptsReturn" 
             Width="300" Height="150" TextWrapping="Wrap" TextAlignment="Center" MaxLength="500" AcceptsReturn="True" />
    <TextBox Margin="20,20,0,0" Text="A text box that demonstrates HorizontalScrollBarVisibility and VerticalScrollBarVisibility" 
             Width="300" Height="150" AcceptsReturn="True" HorizontalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible" />
</StackPanel>



public Page()
{
    InitializeComponent();
    CreateControls();
}

private void CreateControls()
{
    //Create stack panel
    StackPanel MyStackPanel = new StackPanel();

    //Create the first text box
    TextBox MyTB1 = new TextBox();
    MyTB1.Width = 300;
    MyTB1.Height = 150;
    MyTB1.Text = "A text box that demonstrates TextWrapping, TextAlignment, MaxLength and AcceptsReturn";
    MyTB1.TextWrapping = TextWrapping.Wrap;
    MyTB1.TextAlignment = TextAlignment.Center;
    MyTB1.MaxLength = 500;
    MyTB1.AcceptsReturn = true;
    MyTB1.Margin = new Thickness(20, 20, 0, 0);

    //Create the second text box
    TextBox MyTB2 = new TextBox();
    MyTB2.Margin = new Thickness(20, 20, 0, 0);
    MyTB2.Text = "A text box that demonstrates HorizontalScrollBarVisibility and VerticalScrollBarVisibility";
    MyTB2.Width = 300;
    MyTB2.Height = 150;
    MyTB2.AcceptsReturn = true;
    MyTB2.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
    MyTB2.VerticalScrollBarVisibility = ScrollBarVisibility.Visible;

    //Add the text boxes to the stack panel
    MyStackPanel.Children.Add(MyTB1);
    MyStackPanel.Children.Add(MyTB2);
    this.Content = MyStackPanel;
}


Windows Phone OS

受以下版本支持: 8.0, 7.1, 7.0

Windows Phone

显示: