WPF异常:在“System.Windows.Markup.StaticResourceHolder”上提供值时引发了异常。


异常背景:

  第一次开发 WPF 时,所有资源都定义在 App.xaml 文件中。随着项目资源的增多,查看与修改资源时很麻烦,就在 App.xaml 以集成资源字典的方式。

异常原因:

  在 App.xaml 中定义资源时,我把项目中需要使用的 Class 都写在最上面   

<Application.Resources>
  <app:ColorCollection_Column x:key="C_CCC"/>
  ...
</Application.Resources>       
App.xaml

   在 App.xaml 中集成资源字段时,我把 Class 与 其它资源分开

<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>
资源字典 - Class
<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 资源的引用 )在前,所以报错。


 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM