Hel...">

How to split TextBlock Text to DynamicResource in WPF

here, i have a resource on the page

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

      

I want to localize my application with DynamicResource, so the Text property of my TextBlock is a reference to this DynamicResource

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

      

I prefer the word "Hello" on the first line and "World" on the second line, so I use "& #aa;" but this is treated as a space.

If I directly bind the string "Hello & # xa; The world" to TextBlock.Text

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

      

it will break properly.

So how do you split a string into a DynamicResource?

+3


source to share


1 answer


Add xml:space="preserve"

to definitionString



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

      

+1


source







All Articles