在WPF文本框中,enter不会添加新的行

时间:2022-11-29 10:41:43

Text box is defined in following code:

文本框定义如下:

<TextBox Grid.Row="2" IsReadOnly="{Binding IsDescriptionReadOnly}" AcceptsReturn="True"
                                 TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Text="{Binding Description, UpdateSourceTrigger=PropertyChanged}"/>e

When enter is pressed, a new line is not inserted. How to fix this problem?

按下enter时,不会插入新的行。如何解决这个问题?

3 个解决方案

#1


74  

I had similar problem, I solved it with this question using AcceptsReturn="True". So I think, this should work.

我也遇到过类似的问题,我用AcceptsReturn="True"解决了这个问题。所以我认为,这应该是可行的。

#2


4  

What you have should work fine, assuming

假设你应该工作得很好!

  1. IsReadOnly is false. If you set this to true, then obviously the Enter key won't work.
  2. IsReadOnly是错误的。如果将其设置为true,那么显然Enter键不能工作。
  3. The control containing the TextBox is not clipping the TextBox, so it appears that the Enter key did not work.
  4. 包含文本框的控件没有剪切文本框,因此似乎输入键不起作用。

I'd suggest you try this outside of your project to get a better indication of the actual issue.

我建议您在项目之外尝试一下,以便更好地了解实际问题。

#3


4  

Add the following:

添加以下:

TextBox.AcceptsReturn = True;

#1


74  

I had similar problem, I solved it with this question using AcceptsReturn="True". So I think, this should work.

我也遇到过类似的问题,我用AcceptsReturn="True"解决了这个问题。所以我认为,这应该是可行的。

#2


4  

What you have should work fine, assuming

假设你应该工作得很好!

  1. IsReadOnly is false. If you set this to true, then obviously the Enter key won't work.
  2. IsReadOnly是错误的。如果将其设置为true,那么显然Enter键不能工作。
  3. The control containing the TextBox is not clipping the TextBox, so it appears that the Enter key did not work.
  4. 包含文本框的控件没有剪切文本框,因此似乎输入键不起作用。

I'd suggest you try this outside of your project to get a better indication of the actual issue.

我建议您在项目之外尝试一下,以便更好地了解实际问题。

#3


4  

Add the following:

添加以下:

TextBox.AcceptsReturn = True;