• 'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.'


    产生这个错误的原因是,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。

  • 相关阅读:
    Myeclipse 安装svn插件
    Http状态码详解
    myeclipse中的js文件报错
    eclipse 反编译插件安装
    ecshop绕过验证码暴力破解
    Myeclipse中全部文件设置成UTF-8
    WampServer phpadmin apache You don't have permission to access
    如何在Win8系统上建立WIFI热点
    记录远程桌面登录者的IP和MAC
    数据库总结
  • 原文地址:https://www.cnblogs.com/syqun/p/resource.html
Copyright © 2020-2023  润新知