2

I have a WPF application (Project A) in which i have a Resource Dictionary file Global.xaml. In this file i am refering

<BitmapImage x:Key="Test" UriSource="..\Images\Test.png">

The above line references the image from the below path

pack://application:,,,/Assembly of Project A;component/Images/Test.png

Now i am moving the image to a Shared project (Shared Project A) and is referenced in Project A. So what would be UriSource?

I tried giving Assembly of Shared Project A;component/Images/Test.png

but it is not taking the image from shared project.

Marc
  • 19,394
  • 6
  • 47
  • 51
Venkat Ramanan
  • 217
  • 2
  • 8
  • Related question in case you run into trouble with this: [*Pack URI to image embedded in a resx file*](https://stackoverflow.com/q/16409819/109702) – slugster Jan 23 '18 at 09:02

1 Answers1

-1

Try this:

General:

Source="pack://application:,,,/<ReferencedAssemblyName>;component/<PathInReferencedAssembly>"

In your case:

Source="pack://application:,,,/SharedProjectA;component/Images/Test.png"

Also make sure the Build-Action is Resource for all of your Images and the project is built successfully.

Felix D.
  • 4,811
  • 8
  • 38
  • 72
  • 2
    This solution does not work for me, it throws `FileNotFoundException` because it is trying to find `SharedProjectA` assembly, but such assembly does not exist because shared projects do not create own assemblies. I am playing with almost empty solution and I have a strange problem: I have an image in folder `SharedProject/Images/image.png`. When I reference it as `/Images/image.png` it correctly shows up in designer, but not in runtime. On the other hand when I reference it without path as `image.png`, it does not show in designer, but works in runtime :( – Honza Vojtěch Mar 16 '21 at 12:19
  • Yep, shared project does not produce an assembly. I was able to load picture after using main assembly name, not shared one: `Source="pack://application:,,,/MyLibraryAssemblyName;component/Images/Test.png"` – Dmitriy Vornychev Jan 18 '23 at 17:22