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!
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.
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.
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.
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">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With