Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using tab and carriage return character in a WPF resource dictionary

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.

like image 773
AliRezza Avatar asked Oct 20 '11 11:10

AliRezza


2 Answers

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&#x09;Test&#x0d;Test</system:String>
like image 119
Johannes Kommer Avatar answered Nov 07 '22 05:11

Johannes Kommer


Add newline like so &#x0d;&#x0a; and tab with &#x09;

However this won't work unless you've turned off white-space normalization as J.Kommer suggests

like image 44
Muhammad Hasan Khan Avatar answered Nov 07 '22 06:11

Muhammad Hasan Khan