Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to merge ResourceDictionary from a referenced project

I have two assemblies that each provide a common set of styles and resources that I want to include in my application. I'm using merged dictionaries in my App.xaml in order to load them, and at runtime they were just fine. Unfortunately, these resources won't load at design time, filling my Errors window with messages about unresolvable resources and giving me a UI that doesn't represent what will actually appear.

This is my App.xaml as it stands right now:

<Application x:Class="ClientDebug.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             >
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Dai.Common;component/Xaml/Common.xaml" />
                <ResourceDictionary Source="/Dai.DevExpress;component/Xaml/Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

For both of these merged dictionaries, I get the following errors in my Errors window:

Error   11  An error occurred while finding the resource dictionary "/Dai.Common;component/Xaml/Common.xaml".   C:\DevProjects\Core Application\ClientDebug\App.xaml    12  17  ClientDebug
Error   12  An error occurred while finding the resource dictionary "/Dai.DevExpress;component/Xaml/Styles.xaml".   C:\DevProjects\Core Application\ClientDebug\App.xaml    13  17  ClientDebug

Which are obviously short on helpful information. Again, they load at runtime just as you'd expect, but none of the resources are available at design time.

like image 682
Adam Robinson Avatar asked Nov 12 '22 22:11

Adam Robinson


1 Answers

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.

like image 200
Burton Radons Avatar answered Nov 15 '22 12:11

Burton Radons