Ivan
Ivan

Reputation: 588

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?

Upvotes: 46

Views: 37649

Answers (3)

Hooman
Hooman

Reputation: 49

Add the following:

TextBox.AcceptsReturn = True;

Upvotes: 5

VilemRousi
VilemRousi

Reputation: 2142

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

Upvotes: 103

CodeNaked
CodeNaked

Reputation: 41393

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.

Upvotes: 6

Related Questions