<?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)解决办法
用 来代替空格。
<system: String x:Key="UID_Refresh">  Refresh </system :String>