when I use this code in xaml
Image Source="pack://\icons\th.jpg"
I got this
Error Could not find a part of the path 'C:\Users\Sam-a\source\repos\RetailManager\RMWpfDesktopUI
Image Source="\RMWpfDesktopUI\icons\th.jpg" not working too'
but the code below works (but this is not a relative path
Image Source="C:\Users\Sam-a\source\repos\RetailManager\RMWpfDesktopUI\icons\th.jpg"
What i can do?????
Asked
Active
Viewed 102 times
0
awadallah ayman
- 5
- 4
-
You can check documentation: https://docs.microsoft.com/en-us/dotnet/desktop/wpf/app-development/pack-uris-in-wpf?view=netframeworkdesktop-4.8 – Auditive Oct 23 '21 at 11:35
-
`...Image Source="icons/th.jpg"` probably should work if your `th.jpg` stored in `icons` subfolder of your application. – Auditive Oct 23 '21 at 11:38
-
no when I use icons/th.jpg I got Error Could not find file 'C:\WINDOWS\System32\icons%5Cth.jpg'. – awadallah ayman Oct 23 '21 at 11:53
-
You have your `ShellView.xaml` in `Views` subfolder. To use relative path you should add dots `.` at beginning (`../icons/th.jpg`) or use absolute path through `pack://application:,,,/icons/th.jpg`. – Auditive Oct 23 '21 at 11:56
-
the ../ give me the same error but pack: give me diferent error Error Cannot locate resource 'icons/th.jpg'. RMWpfDesktopUI C:\Users\Sam-a\source\repos\RetailManager\RMWpfDesktopUI\Views\ShellView.xaml 43 by the way thank you very much – awadallah ayman Oct 23 '21 at 12:05
-
In case your intention is to load an image from an assembly resource file (which is not really clear, but may be assumed due to the pack:// prefix somewhere in your question), make sure to add the file to your Visual Studio project - in a project folder called icons - and set its Build Action to Resource. Please read through the answers to the duplicate questions – Clemens Oct 23 '21 at 16:36
-
solved the relative path is "../icons/th.jpg" and not "..\icons\th.jpg" thanks guys for helping – awadallah ayman Oct 25 '21 at 12:42