using tab and carriage return character in a WPF resource dictionary

房东的猫 提交于 2019-12-22 01:42:08

问题


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&#x09;Test&#x0d;Test</system:String>



回答2:


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



来源:https://stackoverflow.com/questions/7835260/using-tab-and-carriage-return-character-in-a-wpf-resource-dictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!