Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image Source in WPF

Tags:

c#

wpf

xaml

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!

like image 672
Ryan Avatar asked Jun 26 '14 13:06

Ryan


People also ask

How do I insert an image in WPF?

WPF image control is a versatile control. We will add the image by using the Syntax: Image Source property. Source Property: We use Source Property to define the image which we want to display. We use source property inside the Image Control to identify the image which we want to display.

How do you change the source of an image in UWP?

Here's how to set the source to an image from the app package. Image img = new Image(); BitmapImage bitmapImage = new BitmapImage(); Uri uri = new Uri("ms-appx:///Assets/Logo.png"); bitmapImage. UriSource = uri; img. Source = bitmapImage; // OR Image img = new Image(); img.

What is Bitmapsource?

Bitmap (BMP) is an image file format that can be used to create and store computer graphics. A bitmap file displays a small dots in a pattern that, when viewed from afar, creates an overall image.


1 Answers

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">
like image 106
Sheridan Avatar answered Sep 28 '22 02:09

Sheridan