Search code examples
c#wpfshared-project

WPF Accessing image path from shared project


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.


Solution

  • 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.