In WPF textBox, enter does not add a new line

2019-03-17 04:37发布

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?

3条回答
做个烂人
2楼-- · 2019-03-17 05:01

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

查看更多
祖国的老花朵
3楼-- · 2019-03-17 05:05

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. The control containing the TextBox is not clipping the TextBox, so it appears that the Enter key did not work.

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

查看更多
虎瘦雄心在
4楼-- · 2019-03-17 05:09

Add the following:

TextBox.AcceptsReturn = True;
查看更多
登录 后发表回答