3

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?

RambleInX
  • 143
  • 11

1 Answers1

1

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>
dkozl
  • 32,814
  • 8
  • 87
  • 89
  • Thanks! It worked! But, I have another doubt. In this way, I have to add `code`xml:space="preserve"`code` to every resource that need to break. Is there any better way to notify every resource that its space should preserved? – RambleInX Jun 06 '15 at 11:29
  • Unfortunately I think you'll have to add it every resource. Technically you should be able to apply it to parent (and it would apply to all children) but XAML complains that it's not allowed – dkozl Jun 06 '15 at 11:43
  • Yeah,It is. Thank you! – RambleInX Jun 06 '15 at 13:08