wpf 在WPF textBox中,回车不添加新行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6829261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In WPF textBox, enter does not add a new line
提问by Ivan
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?
按下回车键时,不会插入新行。如何解决这个问题?
回答by VilemRousi
I had similar problem,
I solved it with this questionusing AcceptsReturn="True"
. So I think, this should work.
我有类似的问题,我解决它这个问题使用 AcceptsReturn="True"
。所以我认为,这应该有效。
回答by CodeNaked
What you have should work fine, assuming
你所拥有的应该可以正常工作,假设
- IsReadOnly is false. If you set this to true, then obviously the Enter key won't work.
- The control containing the TextBox is not clipping the TextBox, so it appears that the Enter key did not work.
- IsReadOnly 为假。如果您将此设置为 true,那么显然 Enter 键将不起作用。
- 包含 TextBox 的控件没有剪切 TextBox,因此 Enter 键似乎不起作用。
I'd suggest you try this outside of your project to get a better indication of the actual issue.
我建议您在项目之外尝试此操作,以更好地了解实际问题。
回答by Hooman
Add the following:
添加以下内容:
TextBox.AcceptsReturn = True;