In WPF textBox, enter does not add a new line

萝らか妹 提交于 2019-12-20 16:13:41

问题


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?


回答1:


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




回答2:


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.




回答3:


Add the following:

TextBox.AcceptsReturn = True;


来源:https://stackoverflow.com/questions/6829261/in-wpf-textbox-enter-does-not-add-a-new-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!