Avoiding Visual Studio designer errors when WPF resource is defined in separate project

You could create your own ResourceDictionary class, inheriting from ResourceDictionary.
Then you can arrange that at design-time this custom ResourceDictionary loads some explicitly defined styles (i.e. those loaded from the app at runtime), whereas at runtime it does nothing at all.
The IsInDesignMode-Property could be evaluated for this.

Say you have such a class, called ‘DesignTimeResourceDictionary’, then you just use s.th. like

 <UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <Util:DesignTimeResourceDictionary Source="SomeUriToYourResources"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
 </UserControl.Resources>

to load your resources at design-time and make the designer work.
At Runtime you can then make your DesignTimeResourceDictionary skip the loading of resources and achieve the desired behavior.

If you need, you could really create a copy of the real resources for this, or you can just create a dummy dictionary containing all the keys you need to keep the designer working.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)