Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In WPF textBox, enter does not add a new line

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?

like image 337
Ivan Avatar asked Jul 26 '11 11:07

Ivan


People also ask

How do I create a line break in TextBlock WPF?

Adding Line Breaks Sometimes you will want to insert a line break within a TextBlock. You can do this with a LineBreak inline, added as an XAML element within the text. A new line will be started at the position of this element.

How do I add a TextBox in XAML?

Here's how to create a TextBox in XAML and in code. TextBox textBox = new TextBox(); textBox. Width = 500; textBox. Header = "Notes"; textBox.


2 Answers

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

like image 144
VilemRousi Avatar answered Oct 14 '22 21:10

VilemRousi


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.

like image 30
CodeNaked Avatar answered Oct 14 '22 20:10

CodeNaked