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.
Use Shift + Enter to insert a new line.
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.
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.
Answers. You can also use Shift + Enter in the resource editor...
Working solution: shift+enter in the dictionary resource window in visual studio seems to work.
Try to add xml:space="preserve"
to your resource and use
<sys:String x:Key="MyString" xml:space="preserve">line1 line2</sys:String>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With