考虑文件|为什么Generic.xaml中的合并字典需要绝对uri?
- 命名CustomControl1 名为Dictionary1和Dictionary2
- 两个新的资源字典新的自定义控制
就拿产生的样式当中Generic.xaml和移动它:包含一个WPF应用程序的新项目到Dictionary2。然后合并成Dictionary2和Dictionary1到Dictionary1一般是这样的:
<!--Generic.xaml-->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/Themes/Dictionary1.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!--Dictionary1.xaml-->
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionary2.xaml"/>
</ResourceDictionary.MergedDictionaries>
然后,添加CustomControl1的实例到主窗口的网格。 (这个部分是重现问题所必需的,项目总是编译得很好 - 只是在运行时才会出现问题,并且必须参考字典。)
在Dictionary1.xaml中,我正在合并另一个字典文件夹,所以一个简单的Source =“Dictionary2.xaml”就起作用。然而在Generic.xaml中,我必须使用绝对URI。如果我将上面的内容更改为Source =“Dictionary1.xaml”,而没有使用pack://应用程序东西,那么当它尝试构造MainWindow时,我得到由IOException导致的XamlParseException“Can not locate resource'dictionary1.xaml'”。
我的问题:关于相对URI解析的generic.xaml有什么特别之处?为什么?