Unable to merge ResourceDictionary from a referenced project

两盒软妹~` 提交于 2019-12-03 15:52:48

I have this every time I start a new WPF project or work with an old one ever since a few days ago. I started a question to ask for help on it, only for it to disappear on me on a test Solution! Seems Visual Studio's not very stable, who knew?

The core of the problem is that the Xaml designer isn't allowing you to make references to other Projects in your Solution from your Application Project only. The workaround is to move everything into a Library and have the Application do little more than hand off control to it in code. Inelegant and the loss of App.Xaml is very tough, but it's much better than waiting for Visual Studio to magically figure it all out.

I precede the dictionaries that are from other namespaces with "pack://application:,,," like so:

        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/Wsi.Util;component/DataGrid/NameValueDataGridDictionary.xaml" />
            <ResourceDictionary Source="LayoutStylesDictionary.xaml" />
            <ResourceDictionary Source="pack://application:,,,/Wsi.Util;component/controls/ToolBarResources.xaml" />
            <ResourceDictionary Source="pack://application:,,,/Wsi.Common;component/view/themes/FilterStylesResourceDictionary.xaml" />
        </ResourceDictionary.MergedDictionaries>

HTH,

Janene

I tried a similar merging in a project of mine and I seem to have it working perfectly. (or so, forgive me if its some settings of mine that I may have set long ago..) The only question I can ask is if the xamls are referring to anything within the parent project? I am assuming you have a reference to the parent project also (just cross-checking). Maybe the xaml file needs another xaml file too (controls, colors, fonts etc). (The merging that I tried was from MahApps.)

  <Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>

I fixed this issue by signing the referenced project.

Problem was: My project was signed with a key file but the referenced project not.

To solve:

  • Load the project into the solution
  • Opened the project properties
  • Navigate to 'Signing'
  • Click 'Sign the assembly'
  • Select '<New...>' from the combo box
  • Enter a name, eg. 'keyfile' ('Protect my keyfile with a password' is optional)
  • Rebuild solution
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!