XAMLMarkupExtensions/WPFLocalizeExtension

Newlines do not seperate text into seperate lines when bound.

Code-Reaper opened this issue · 4 comments

Hello,

I was looking for some guidance regarding newlines. I am using this extension with the ResX resource manager and I am having issues getting newlines to work.

Consider a text block...
<TextBlock x:Name="ATextBlock" Text="Line1&#x0a;Line2" />

This shows the text correctly on two separate lines.

Line1
Line2

If I then make this into an entry in the resource manager and bind it to my text block...
<TextBlock x:Name="ATextBlock" Text="{lex:Loc}" />

The text shown in the UI is, "Line1 Line2", all on a single line. I have tried all forms of new lines in these strings, but each time it appears the extension is treating everything as just text. The only success I have found so far is to open a text editor and copy and paste the CRLF characters out of it and paste that into the resource manager where the newline would go. While this does work, I am curious if there is a better way that I just didn't see in the docs or online?

Thank you.

konne commented

@Karnah do you have a chance to check this and give an answer?

Hello, @Code-Reaper.
Hmm, it's stange. I checked it on HelloWorldWPF.sln, it's working.

image

I use Visual Studio and create new line with "Shift + Enter" combination.

Hello @Karnah

I can confirm that using your method it does work and new lines are generated correctly. I figured that it was supposed to allow for the normal values that you could put into a XAML designer file like, "& #x0a;" (without the space in it). If that wasn't supposed to be the design then we can close this out as completed.

For anyone else that stumbles upon this seeking a code-based approach I ended up writing a method that I used for certain keys that automatically searched for and replaced, "\n", "\r\n", and & #x0a; values in the string with actual newlines before it was returned to the control.

Thanks everyone.

Symbols &#x0a; are used only in the XAML file, because it doesn't support CR LF directly. Instead of this XAML parser automatically replaces &#x0a; with CR LF and puts a new string in TextBlock.Text (you can check it throw debug).
For any other string resources, you should use CR LF