Kyle Williamson
Kyle Williamson

Reputation: 2184

Text column copied from Excel does not paste correctly into WPF TextBox

I have a simple WPF application with an empty TextBox. I would like the user to be able to copy rows of text (from one column) in Excel and paste the contents into the TextBox. My app will then format the text in a certain way.

When I paste the copied rows, the TextBox only contains the first row. WPF app with pasted rows

When I paste into Notepad all the items are pasted correctly. Rows pasted into Notepad with correct formatting

How can I get the same effect in my WPF app?

I have tried changing TextWrapping to NoWrap, Wrap, WrapWithOverflow. MaxLines is set to 2147483647. I don’t see any other Properties that make sense to change.

Upvotes: 0

Views: 712

Answers (1)

mm8
mm8

Reputation: 169170

It should work if you set the AcceptsReturn property of the TextBox to true:

<TextBox AcceptsReturn="True" Height="100" />

Upvotes: 1

Related Questions