microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

TextBox.AcceptsReturn lost \n in UWP

Open vsfeedback opened this issue 5 years ago • 8 comments

This issue has been moved from a ticket on Developer Community.


I set TextBox.AcceptsRetrun = true in UWP project.

When I key down Enter and new line the content, the TextBox.Text don't provider \n , only got \r.

I test WPF project, it don't have the issue.

reference the link: https://stackoverflow.com/questions/42498195/uwp-textbox-is-missing-the-line-feed-n-character-in-windows-10-build-14393

TextBox lost \n already be happen on Windows 10 (14393).


Original Comments

Visual Studio Feedback System on 1/2/2020, 06:10 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

vsfeedback avatar Jan 09 '20 23:01 vsfeedback

@ddalp Do you know if there's any standing issues with this, or has the behavior always diverged from WPF?

chrisglein avatar Jan 23 '20 19:01 chrisglein

@chrisglein XAML TextBox had this behavior since RS1, it is because richedit internally using the \r in its data store for line breaker while XAML converts text back with "\r\n". Some of the TextBox API will have problem if it has something to do with the text position(i.e. SelectionStart) or length(Length, MaxLength), since we pass it back and forth with RichEdit directly. So in RS1, we switched to "\r" to be consistent with richedit.

To fix it, we need RichEdit to support configurable line breaker for its internal data store which XAML can ask it to use "\r\n" instead of "\r".

ddalp avatar Jan 23 '20 19:01 ddalp

TextBox should write Environment.NewLine when you hit Enter. It's totally unacceptable. Please revert the code to the correct behaviour and fix richedit elsewhere. It was a bad fix which should be rolled back. I share code with Android xamarin and all new lines are stripped off in android app because of this bug. Lines are merged into one line. I don't think it should be fixed on my side in my code. While it's not critical when you use one platform it's a breaking feature for crossplatform code. Please fix it.

Mogikan avatar Aug 21 '20 13:08 Mogikan

Seeing similar regression issue. Is there a fix planned for this or flag to adjust behavior? StringBuilder should handle this use case?

https://docs.microsoft.com/en-us/dotnet/api/system.environment.newline?view=net-5.0 NewLine is automatically appended to text processed by the Console.WriteLine and StringBuilder.AppendLine methods.

asears avatar Jan 29 '21 17:01 asears

This is nuts, the only platform I'm familiar with that uses \r line endings is classic MacOS.

Is there any plans to fix this, because I'm now needing to shim my data coming out of WinUI because no other platform knows how to process \r line endings.

For anyone looking for a work around, best I came up with 5 minutes of thinking about the problem in my space was to use a converter which calls ReplaceLineEndings.

knightmeister avatar May 29 '23 21:05 knightmeister

Please fix this bug!

doggy8088 avatar Oct 27 '23 12:10 doggy8088

Unfortunately this would be a breaking change. What we need to do is add the property to TextBox to choose one over the other and keep the default the same. Switching this to a feature proposal.

ranjeshj avatar Nov 21 '23 00:11 ranjeshj

Any plans to tackle this issue in the near future? I'm having the same problems in our UWP app and to say the least: This behavior does not match any other newline delimiter on Windows at all!

Matthias-Heinz avatar Feb 09 '24 12:02 Matthias-Heinz

Again, a strange thing for Microsoft to wait years for such an annoying little thing... If someone out there does notice this bug..

mimregit avatar Mar 27 '24 12:03 mimregit