user2529011
user2529011

Reputation: 743

Referencing resource dictionaries from an external project

Is it possible to make a resource dictionary in a separate library (framework) project and then reference it in another library project? In this separate project I have a UserControl that wants to use it.

This is my how my solution is set up.

enter image description here

SharedProject has the resource dictionaries and I reference it in my Plugin project. I then export my Plugin library into MainProject and have it displaying my views from Plugin.

I have all this working... except for my dictionaries. I have tried referencing my dictionaries in each of my views

<UserControl.Resources>  
        <ResourceDictionary x:Key="dictionary">
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/InternalShared;component/Resources/Dictionary1.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/InternalShared;component/Resources/Dictionary2.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

But when I try to reference an existing style...

<Button     Command="{Binding CommandOpenFile}"
            Style="{DynamicResource GenericButtonStyle}" 
            IsEnabled="{Binding IsEnabled}"
            Content="Restore Window" 
            Height="Auto" />

But I get The resource "GenericButtonStyle" could not be resolved. This is happening everywhere I try refernce the style in any of my dictionaries. I don't know why.

Can anyone tell me why this is happening? Is there somewhere else I need to set this declaration?

Upvotes: 1

Views: 1102

Answers (1)

Keithernet
Keithernet

Reputation: 2509

I maintain an external WPF UI library that is used by many different solutions.

  • Make sure InternalShared is a WPF DLL
  • Merge in your external resources into the App.xaml of your main WPF app instead

For instance, applications using my resources merge them in like this:

<ResourceDictionary Source="/InternalShared;component/Resources/Dictionary1.xaml"/>

Upvotes: 2

Related Questions