Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Line breaks in string resources

Tags:

string

c#

wpf

In my WPF application I'm referencing strings from a centralized dictionary resource. How can I put line breaks in these strings?

I tried "line1\nline2", "line1\\nline2" and "line1
line2", but none are working.

I should mention that I'm also including tokens in these strings ({0},...) and later using string.format(resource, args) in run-time.

like image 388
liorda Avatar asked Aug 28 '14 09:08

liorda


People also ask

How do you insert a line break in resources?

Use Shift + Enter to insert a new line.

How do I create a line break in TextBlock WPF?

Adding Line Breaks Sometimes you will want to insert a line break within a TextBlock. You can do this with a LineBreak inline, added as an XAML element within the text. A new line will be started at the position of this element.

How do you insert a line break in XAML?

XAML attributes of type String may contain any special characters, as long as those are referenced as hex-codes. For example, a simple line break ( \n ) would be represented as 
 , for \r\n you'd use 
 and so on.

How do I add a new line in Resx?

Answers. You can also use Shift + Enter in the resource editor...


2 Answers

Working solution: shift+enter in the dictionary resource window in visual studio seems to work.

like image 152
liorda Avatar answered Sep 29 '22 08:09

liorda


Try to add xml:space="preserve" to your resource and use 

<sys:String x:Key="MyString" xml:space="preserve">line1&#13;line2</sys:String>
like image 27
IVAAAN123 Avatar answered Sep 29 '22 08:09

IVAAAN123