Xaml中string(字符串)常量的定义以及空格的处理

原文: Xaml中string(字符串)常量的定义以及空格的处理

<?xml version="1.0" encoding="UTF-8"?>
(1)基本用法
xaml中可以实例化各种对象,比如在ResourceDictionary中定义字符串常量:

< 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">
   
    < FontFamily x : Key ="UID_GlobalFont_Family"> Microsoft YaHei </ FontFamily >
    < system : String x : Key ="UID_Refresh">   Refresh  </ system : String >
</ResourceDictionary>


上述资源字典中定义了字符串常量UID_Refresh, 实际使用步骤:
1.在使用的xaml通过ResourceDictionary.MergedDictionaries导入上述资源

<UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/XXXXXXXXXXXXXXX;component/XXXXXXXXXXX.xaml" />
            </ResourceDictionary.MergedDictionaries>
         </ResourceDictionary>
    </UserControl.Resources >
     
2.通过DynamicResource 或者 StaticResource来引用这个字符串常量
< TextBlock   Text ="{ DynamicResource UID_Refresh }"  />



(2)存在的问题
上述UID_Refresh的定义有空格,实际显示却没有空格


(3)解决办法
&#160;来代替空格。

<system: String x:Key="UID_Refresh"> &#160;Refresh&#160;</system :String>
posted on 2018-03-10 00:01 NET未来之路 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/lonelyxmas/p/8537056.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值