在 WPF 资源字典中使用制表符和回车符 [英] using tab and carriage return character in a WPF resource dictionary

查看:53
本文介绍了在 WPF 资源字典中使用制表符和回车符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 WPF XAML 资源字典中使用制表符和回车符?

How can I use tab and carriage return characters in a WPF XAML resource dictionary?

这对我不起作用:

<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>

当我通过 FindResource("test_key") 检索它时,制表符和回车符都被删除了.

when I retrieve this via FindResource("test_key"), both the tab and carriage return characters are removed.

推荐答案

XAML 解析器使用空白规范化(根据 MSDN) 如果您想避免这种情况,请将 xml:space="preserve" 添加到您的 XML 中:

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>

这篇关于在 WPF 资源字典中使用制表符和回车符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆