Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to break TextBlock's Text by DynamicResource in WPF

here, I am have a Resource in Page

<Page.Resources>
    <sys:String x:Key="textBlock1">Hello&#xa;The world</sys:String>
</Page.Resources>

I want to localize my application by using DynamicResource, therefore, the Text property of my TextBlock is reference to this DynamicResource

<TextBlock Text="{DynamicResource textBlock1}" Margin="105,163,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />

I prefer the word "Hello" in the first line and "The world" in the second line, so I use " ", but it is treated as a space.

If I assign string "Hello The world" to TextBlock.Text directly

<TextBlock Text="Hello&#xa;The world" Margin="105,163,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />

it break correctly.

So, how to break string in DynamicResource?

like image 594
RambleInX Avatar asked Dec 19 '25 12:12

RambleInX


1 Answers

Add xml:space="preserve" to your String definition

<Page.Resources>
    <sys:String xml:space="preserve" x:Key="textBlock1">Hello&#xa;The world</sys:String>
</Page.Resources>
like image 73
dkozl Avatar answered Dec 21 '25 04:12

dkozl