0

I have a class library that is essentially a collection of forms to be run. Consider it a module/plugin in a larger program, that can be developed independently, all the larger program cares about is the DLL (and interface).

Running the main form of the class library is fine and works well. My issue is with pictures. I've set up an Images folder in the class library, added an image, set it's Build Action to Embedded Resource and then rebuilt the project, but the images won't appear in the main program.

XAML:

<Button x:Name="btnAdd" Command="{Binding Add}">
    <StackPanel Orientation="Horizontal">
        <Image x:Name="imgAdd" Source="Resources/Add.png"/>
        <Label>New</Label>
    </StackPanel>
</Button>

The interesting part though, is that if I create a BitmapSource in code-behind and assign it to imgAdd in the constructor of the form, it works as expected. Does anyone have any ideas as to why this might be the case?

Trent
  • 1,595
  • 15
  • 37

2 Answers2

0

Use Pack URIs for your images.

<Button x:Name="btnAdd" Command="{Binding Add}">
    <StackPanel Orientation="Horizontal">
        <Image x:Name="imgAdd" Source="pack://application:,,,/ReferencedAssembly;component/Resources/Add.png"/>
        <Label>New</Label>
    </StackPanel>
</Button>
dymanoid
  • 14,771
  • 4
  • 36
  • 64
  • OK, that looks promising. I'm still having trouble through, it doesn't display still. The resources/images are in the same DLL as the form (XAML above). The main program calls a method `ShowMainForm()` on the DLL which causes the form to show. The main program doesn't know or care about the form or images, it just tells the DLL to display it. – Trent Jan 28 '15 at 00:10
0

It turns out that the correct Build Action is actually Resource rather than Embedded Resource. Thinking about it now, Embedded Resource does seem more like a reference to a Resource in another DLL.

I inadvertently found the answer in this post while trying to improve my code.

Community
  • 1
  • 1
Trent
  • 1,595
  • 15
  • 37