Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8869047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:23:33+00:00 2026-06-14T17:23:33+00:00

I’m writing a modular application using Microsoft Prism and Unity. My application’s Shell project

  • 0

I’m writing a modular application using Microsoft Prism and Unity. My application’s Shell project loads various DLLs which all include their own /resources or /images folder and user interface views. Each module, therefore, is a DLL.

When I’m trying to use a resource in my application, it seems I have to be very explicit about its location to make it work. For example, to locate an image in the same module/dll:

<Image Source="pack://application:,,,/MyCompany.MyProduct.MyModule;Component/Images/ZoomIn.gif" />

Do I really have to use the long form version of the URI everytime? I’ve tried shorter versions such as:

pack://application:,,,/Images/ZoomIn.gif

Images/ZoomIn.gif

ZoomIn.gif

etc.

I thought perhaps the 2nd version there should work. When I see Uri examples they often say “relative to the current assembly”. Is this the assembly that is the executable that is running? Or is this the assembly that the code belongs to (my library/module)?

Update:

With Peter Hansen’s help, I was able to shorten it to:

<Image Source="../Images/ZoomOut.png" />

Apparently I had to use the ../ because my view was in a subfolder. I also could leave off the pack:// syntax since the type converter does this for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:23:34+00:00Added an answer on June 14, 2026 at 5:23 pm

    There are a few different options when it comes to retrieving binary resources in WPF, and they all depend on which kind of behavior you want.

    1. If your resources should be embedded inside an assembly, add them to the project in Visual Studio, and set the Build Action to Resource. This way they will be baked into the assembly, and therefore can’t be changed easily.

    2. If they should be left as loose files, add them to the project, and set the Build Action to Content. Also make sure they are being copied to the output directory. This is a good idea, if you need to replace them frequently, and don’t feel like recompiling the assembly every time.

    3. If you want them as loose files, but don’t want to include them in your Visual Studio solution for some reason (maybe they are not known at compiletime), you can access them using the full path or with something called SiteOfOrigin notation. I won’t go into this as that is not relevant in your case.

    To access the resources from your code you use a Pack URI, which can have different forms:

    • pack://application:,,,/img.jpg
      References image in the root of the project.

    • pack://application:,,,/Folder1/Folder2/img.jpg
      References image in a subfolder of the project.

    • pack://application:,,,/NameOfDll;Component/img.jpg
      References image in a different assembly to which there is a reference in Visual Studio.

    Luckily there is no need to write the full URI when a resource is referenced from XAML.
    Basically the pack://application:,,, part can be avoided, because a TypeConverter exists that can translate part of the location to the full URI for you.

    For points 1 and 2 above, the same XAML is used to reference the resources, regardless of whether they exist as loose files alongside the assembly at execution time or are embedded inside of it.

    The fully defined explicit URI has to be used when referencing the resources from procedural code, though.

    I have written some code and included some images, to show how this works.

    Image showing running program
    Image of solution explorer view

    Relevant XAML:

    <StackPanel>
        <TextBlock Text="Embedded in same assembly" />
        <Image Source="gift.png" />
    </StackPanel>
    
    <StackPanel>
        <TextBlock Text="Embedded in same assembly in a subfolder" />
        <Image Source="Content/Images/gift.png" />
    </StackPanel>
    
    <StackPanel>
        <TextBlock Text="Embedded in same assembly in a subfolder using full pack URI format" />
        <Image Source="pack://application:,,,/Content/Images/gift.png" />
    </StackPanel>
    
    <StackPanel>
        <TextBlock Text="Embedded in different assembly" />
        <Image Source="/Module1;Component/gift.png" />
    </StackPanel>
    
    <StackPanel>
        <TextBlock Text="Embedded in different assembly in a subfolder" />
        <Image Source="/Module1;Component/Images/gift.png" />
    </StackPanel>
    
    <StackPanel>
        <TextBlock Text="Embedded in different assembly in a subfolder using full Pack URI format" />
        <Image Source="pack://application:,,,/Module1;Component/Images/gift.png" />
    </StackPanel>
    
    <StackPanel>
        <TextBlock Text="Setting imagesource from code-behind" />
        <Image x:Name="image1" />
    </StackPanel>
    

    Relevant code-behind:

    public Window1()
    {
        InitializeComponent();
    
        //Here we have to use the full Pack URI
        //image1.Source = new BitmapImage(new Uri("/Module1;Component/Images/gift.png")); //Throws exception..
        image1.Source = new BitmapImage(new Uri("pack://application:,,,/Module1;Component/Images/gift.png"));
    }
    

    Update
    When the resource is in the same assembly that is using it, there should be no reason to include the /NameOfDll;Component/ part of the URI. I’m not sure why it’s not working in your case.

    I have added a Window to Module1, that just references a single image in its own assembly, and that seems to work fine. The Window is shown when a button is clicked in the WPF application.

    <Window x:Class="Module1.WindowTest"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 mc:Ignorable="d" 
                 d:DesignHeight="300" d:DesignWidth="300"
                 Title="Window from Module1">
        <Grid>
            <Image Source="Images/gift.png" />
        </Grid>
    </Window>
    

    Showing different window with resource shown

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.