Canovas
Canovas

Reputation: 105

WPF pack uri for external assembly that loads local resources

I need to specify a local resource to a external class that I use. I have tried several combinations and I cant make the class load my resources. The resources are compiled with Build Action set to Resource and both dlls are dynamically loaded. I have tried the following URI's based on pack uris in WPF:

  1. External resource loaded from local assembly:

"pack://application:,,,/LocalAssemblyName;component/Resource"

"pack://application:,,,/LocalAssemblyName;/Resource"

  1. Local assembly resource file:

"pack://application:,,,/Resource"

None of them worked. I'd like to know what am I doing wrong.

Upvotes: 1

Views: 1261

Answers (1)

Pollitzer
Pollitzer

Reputation: 1620

In my App.xaml I'm using references to resources located in another assembly like this:

<Application ... >
    <Application.Resources>
        <ResourceDictionary>
            ...
            <!-- This loads a whole ResourceDictionary: -->
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/LocalAssemblyName;Component/ResourcDictionaries/YourResources.xaml" />
            </ResourceDictionary.MergedDictionaries>
            ...
            <!-- Like this you can load resources one by one: -->
            <BitmapImage x:Key="_icon_save" UriSource="pack://application:,,,/LocalAssemblyName;Component/SingleResources\disk12.ICO" />
            ...
        </ResourceDictionary>
    </Application.Resources>
</Application>

Hope it helps.

Upvotes: 1

Related Questions