Xamarin.Froms 3.0 Editor \r\n handling RRS feed

  • Question

  • User212886 posted

    Hi @all,

    I'm, currently developing an UWP app with Xamarin.Forms 3.0 against an existing SQL Server database. Some fields are containing multi line text with \r\n as a line break. When I bind the content of such a field to an Editor control it seems that the Editor immediately sends a normalized version of the text back with only \n as a line break. Example: "Text1\r\nText2\r\nText3" => "Text1\rText2\rText3". This becomes a problem for several reasons: 1. My entity is marked as dirty and the user is ask for saving changes, even nothing has changed. 2. I don't know whether the native Win Forms clients would handle the change properly.

    So my question is: Is there a way to control which character(s) are used for a line break?

    Tanks in advance, Carsten

    Thursday, June 7, 2018 1:48 PM

All replies

  • User89714 posted

    @CarstenGrnzner - That's the behavior I see too (in XF 2.4). It looks like a bug to me - my guess is that somebody thought for cross-platform consistency, text should be normalised (taking into account CR/LF combination on Windows, and LF only on Unix-based platforms). However, rather than leaving it un-normalised (so that the developer is responsible for handling it), or converting CR/LF to LF, it appears that the conversion of CR/LF is being done to CR. If you haven't already, I suggest logging that as a bug.

    Until the bug is fixed, I'd recommend investigating creation of a subclass of Editor and building a corresponding custom renderer.

    Thursday, June 7, 2018 3:44 PM
  • User79778 posted

    This seems to be the issue when switching from one Windows 10 version to Another.

    Also seems reported as a bug here

    I tried to create a custom renderer, replacing "\r" with "\r\n" like this Regex.Replace(editor.Text, "\r(?!\n)", "\r\n"); but it seems like the underlying Control (TextBox) auto-switches it back to only "\r". Frustrating!

    Did anyone successfully created a workaround for this, apart from doing the replacement when presisting the value from the Editor into a Db or whatever? (I'd like to have the workaround on ONE Place, not everywhere data is presisted).

    Friday, May 24, 2019 10:01 AM