为什么找不到同一程序集中的ResourceDictionary?

时间:2017-05-11 15:22:12

标签: wpf xaml resourcedictionary

我已将一些功能/文件从一个解决方案复制到另一个解决方案。

在解决方案1中,我有Windows应用程序DemoApp1,其中包含文件夹:

  • 壳牌
  • 丝带/资源

在Shell / ShellView.xaml

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Ribbon/Resources/Ribbon.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

以上工作没有问题。

在解决方案2中,我使用的Windows应用程序DemoApp2很少。 App-class继承自C#类库DemoApp2Feature中的一个类,它完成了大部分工作。

Shell和Ribbond文件夹结构和文件在类库DemoApp2Feature中是相同的。但是,上面的结果是:

XamlParseException'设置属性'System.Windows.ResourceDictionary.Source'抛出了一个例外'。

当我查看VS2015异常细节时,BaseUri看起来像这样:

{包://应用:,,, / DemoApp2Feature;组分/壳/ shellview.xaml}

我想在DemoApp2Feature中保持文件和文件夹结构相同,因为有许多文件都有这些MergedDictionaries定义。那么我该如何判断为DemoApp2Feature寻找ResourceDictionaries的地方的基础。

1 个答案:

答案 0 :(得分:0)

我不确定我是否完全理解您的方案,但是此页面根据资源的位置解释了包URI的正确格式:

https://msdn.microsoft.com/en-us/library/aa970069(v=vs.110).aspx

enter image description here