产生这个错误的原因是,StaticResource必须先定义再引用,但是DynamicResource就没有这个限制,为避免这个错误出现,可将StaticResource的定义放在Window.xaml的最前端,或者放在App.xaml中,例如:

Window ...>
<Window.Resources>
<xxx x:Key="ExpenseDataSource" />
<DataTemplate x:Key="nameItemTemplate">
....
</DataTemplate>
</Window>
<ListBox>
...
</ListBox>

转自:http://blog.csdn.net/jane_sl/article/details/7389670

但我遇到的问题是一个子工程中的usercontrol报此种错,于是做了以下动作:

1.在主工程的App.xaml中加入了<ResourceDictionary Source="pack://application:,,,/Trisurf;component/Resources/DemoWindowStyles.xaml"/>

2.在子工程的usercontrol的.xaml中加入DataContext="{Binding Source={StaticResource Locator}, Path=***ViewModel}(DataContext不是导致错误的原因,此处只是记录我的修改过程)

  子工程的app.xaml中加入

<Application.Resources>
<ResourceDictionary>
<!--使用资源字典的合并资源功能-->
<ResourceDictionary.MergedDictionaries>
<!--在这里可以指定多个资源文件名-->
<ResourceDictionary Source="Resource/DemoWindowStyles.xaml"/>
</ResourceDictionary.MergedDictionaries>
<vm:ViewModelLocator d3p1:Key="Locator" d:IsDataSource="True"
xmlns:d3p1="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:Trisurf.ViewModel" />
</ResourceDictionary>
</Application.Resources>

OK,问题解决。试了一下,我出现此错误的原因是没有在主程序的App.xaml中加入Resource。

'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.'的更多相关文章

  1. WPF在win7运行时报'Initialization of 'System.Windows.Setter' threw an exception.'

    写的一个WPF程序,在win10运行好好的,在win7就报'Initialization of 'System.Windows.Setter' threw an exception.' 原来是xaml ...

  2. WPF学习笔记——在“System.Windows.StaticResourceExtension”上提供值时引发了异常

    在"System.Windows.StaticResourceExtension"上提供值时引发了异常 因应需要,写了一个转换器,然后窗体上引用,结果就出来这个错.编译的时候没事, ...

  3. debian The type initializer for 'System.Drawing.KnownColors' threw an exception

     Change the "System.Drawing" reference of "CoreCompat.System.Drawing"if you thro ...

  4. the type initializer for 'system.drawingcore.gdiplus' threw an exception

    Centos 7 yum install libgdiplus-devel reboot之后生效 apt install libgdiplus cp /usr/lib/libgdiplus.so ~/ ...

  5. System.Windows.Application.Current.Dispatcher.BeginInvoke

    System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>                        ...

  6. 开发客户端软件时,出现System.Windows.Markup.XamlParseException错误

    开发客户端软件时,出现System.Windows.Markup.XamlParseException错误,通过查看错误消息,发现TCPIP的一个COM组件在安装软件过程中被删除了,重新注册了一下TC ...

  7. WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常

    WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常 在wpf中封装Com组件时,调用组件 ...

  8. 自动化测试 using System.Windows.Automation;

    frameworke3.0 及以上 using System.Windows.Automation; UIAutomationClient.dll UIAutomationClientsideProv ...

  9. System.Security.SecurityException The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

    [15/08/19 00:03:10] [DataManager-7292-ERROR] System.Reflection.TargetInvocationException: Exception ...

随机推荐

  1. C++分布式实时应用框架——系统管理模块

    一个分布式实时系统集群动辄上百台机器,集群的规模已经限定这将是一个”封闭“的系统.你不可能再一台台去操作上百台机器,传统的人工运维方式早已不能满足当下需要,所有对集群或者集群中某个节点的操作都必需通过 ...

  2. 3 Sum leetcode java

    题目: Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find al ...

  3. 敏捷方法之极限编程(XP)和 Scrum区别

    敏捷(Agile)作为一种开发流程, 目前为各大公司所采用, 敏捷流程的具体实践有XP 和Scrum, 似乎很少有文章介绍这两者的区别, 发现一篇外文, 见解非常深刻, 特将其翻译一把. 原文(DIF ...

  4. 一、NoSQL入门概述

  5. 打通Fedora19的vsftpd服务

    Fedora19默认vsftpd也没安,安装界面里也没地方让我选,这一点不如以前的版本人性化.没办法只有自己来了,倒也不费事. 1.下载vsftpd rpm安装包 我是从http://rpmfind. ...

  6. (LeetCode 141/142)Linked List Cycle

    1.Given a linked list, determine if it has a cycle in it. 2.Given a linked list, return the node whe ...

  7. Bootstrap3实现的响应式幻灯滑动效果个人作品集/博客网站模板

    ​在线演示 本地下载 如果你想学习如何开发和使用的话,请参考我们免费的课程: Bootstrap3开发滑动风格的博客网站模板

  8. ArcGIS高程Z值的去除方法

    在ArcGIS中,我们常用的几何类型有点.线.面.体(体,在涉及三维的情况下使用),但在这之外,可能会遇到带ZM的类型,如图所示,面ZM,它与面类似,但比面多两个字段. 在编辑中查看草图属性可看到Z值 ...

  9. IO介绍

    IO在计算机中指Input/Output,也就是输入和输出.由于程序和运行时数据是在内存中驻留,由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘.网络等,就需要IO接口. 比如你打开 ...

  10. PG里如何查看表,索引,表空间,数据库大小

    --查询一个索引大小 select pg_size_pretty(pg_relation_size('indexname)) --查看一张表及此它上的索引总大小select pg_size_prett ...