问题
How can I use tab and carriage return characters in a WPF XAML resource dictionary?
This doesn't work for me:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
>
<system:String x:Key="test_Key">Tab doesnt work\tTest\rTest</system:String>
</ResourceDictionary>
when I retrieve this via FindResource("test_key"), both the tab and carriage return characters are removed.
回答1:
The XAML parser uses whitespace normalisation (as per MSDN) if you want to avoid this add xml:space="preserve"
to your XML as such:
<system:String x:Key="test_Key" xml:space="preserve">Tab doesnt work	Test
Test</system:String>
回答2:
Add newline like so 

and tab with 	
However this won't work unless you've turned off white-space normalization as J.Kommer suggests
来源:https://stackoverflow.com/questions/7835260/using-tab-and-carriage-return-character-in-a-wpf-resource-dictionary