6

I'm trying to set an image source in XAML but keep getting "Could not find part of a path..." (plus the directory I want to call). I think I'm messing up what location I'm supposed to be calling. The hierarchy looks something like:

-Solution
   -Project
      -Data
      -Images
         -Image_I_want_to_use.png (placeholder name)
      -Themes
         -Demo
           -Default
              -fileImWorkingIn.xaml
              -other files
      -other folders
   -Another Project
   -Third Project

How would I configure my image source in XAML so the file I'm working in can utilize the image(s)?

I tried

<Image Source="/Project;component/Images/image_to_use.png">

(where each name is simply a placeholder) but had no luck. Any pointers? Apologies if this is trivial.

Thanks!

3
  • Ugh I just went through this with silverlight, had to manually load the image as BitmapImage, then set an Image.Source = to that BitmapImage, and then databind that to the viewmodel was a pain Commented Jun 26, 2014 at 13:53
  • did you try <Image Source="Images/image_to_use.png"> with image being built as content Commented Jun 26, 2014 at 13:54
  • When you mean image being built as content, you're talking about Build Action under the image's properties, right? If so, I currently have it as a resource. Also, @Pseudo: any good resources for how you did that? Commented Jun 26, 2014 at 14:46

2 Answers 2

7

In .NET 4, this Image.Source value would work:

<Image Source="/AssemblyName;component/FolderName/image_to_use.png">

However, Microsoft made some horrible changes in .NET 4.5 that broke many different things and so in .NET 4.5, you'd need to use the full pack path like this:

<Image Source="pack://application:,,,/AssemblyName;component/Images/image_to_use.png">
Sign up to request clarification or add additional context in comments.

Comments

7

What fixed it:

<Image Source ="pack://application:,,,/Images/image_name.png"></Image>

I also changed the Build Action to content.

Thanks for your help everyone!

1 Comment

this works for .net 8 now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.