2

I am wanting to have a set of styles contained within a standalone dll that can be referenced from a number of different WOF classes to define common styles.

I have created the standalone dll and tried referencing it but am having problems.

Here is the code for the standalone dll:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style x:Key="myStyle" TargetType="Button"> <Setter Property="Background" Value="Orange" /> <Setter Property="FontStyle" Value="Italic" /> <Setter Property="Padding" Value="8,4" /> <Setter Property="Margin" Value="4" /> </Style> <!-- store here your styles --> </ResourceDictionary> 

Here is where Im trying to reference it:

<src:GX3ClientPlugin.Resources> <ResourceDictionary Source="pack://application:,,,/GX3StyleResources.dll;component/GX3StyleResources.xaml" /> </src:GX3ClientPlugin.Resources> 

When running I get the following exception:

Could not load file or assembly 'GX3StyleResources.dll, Culture=neutral' or one of its dependencies. The system cannot find the file specified.

Any Ideas?

1
  • From my experience, it is hard to manage if you keep resources, images, etc in differet project. I also think that it has very little benefit if not none. Commented Oct 19, 2012 at 11:18

2 Answers 2

5

I do the same in some of my projects, what I do is to add the dll as a Reference into my project, then I use the pack Uri but i don't specify the extension .dll. I just use the assembly name (usually withouth .dll)

Source="pack://application:,,,/GX3StyleResources;component/GX3StyleResources.xaml" 
Sign up to request clarification or add additional context in comments.

1 Comment

The problem was that I had .dll on the end of the assembly name.
0

I had this problem before as well. If you never actually reference anything in that assembly in actual C# code, sometimes (the criteria for which I cannot for the life of me determine) the compiler / the runtime / some combination of both just doesn't load or copy your assembly.

Add a class to your resource assembly file that does SOMETHING / anything - don't leave it blank, otherwise it will get optimized away in some cases:

public static class Resources { public static void Init() { Console.Write(string.Empty); } } 

Then, from your application, call Resources.Init() in your App startup method before anything else to ensure the resource assembly gets loaded.

It's a dirty dirty hack, but it works.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.