异常背景:app
第一次开发 WPF 时,全部资源都定义在 App.xaml 文件中。随着项目资源的增多,查看与修改资源时很麻烦,就在 App.xaml 以集成资源字典的方式。ide
异常缘由:spa
在 App.xaml 中定义资源时,我把项目中须要使用的 Class 都写在最上面 code
<Application.Resources> <app:ColorCollection_Column x:key="C_CCC"/> ... </Application.Resources>
在 App.xaml 中集成资源字段时,我把 Class 与 其它资源分开xml
<ResourceDictionary xmlns:app ="clr-namespace:TZCloud" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <app:ColorCollection_Column x:Key="C_CCC"/> </ResourceDictionary>
<ResourceDictionary xmlns:app ="clr-namespace:TZCloud" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> ... </ResourceDictionary>
<Application.Resources> <ResourceDictionary > <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="Dictionary\Other.xaml"/> <ResourceDictionary Source="Dictionary\Class.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>
由于 Class 资源声明在后,而其它资源声明(该资源中有对 Class 资源的引用 )在前,因此报错。blog