Reputation: 2169
I'have this package on my project:
ProjectName : Gestore
---View (Folder)
------Resources (Folder)
---------Images (Folder)
------------immagine1.png
---DatiAnagraficiPageView.xaml
Now I would like to create programmatically an Image, so I try to write this code but it not found. THe code is:
System.Windows.Controls.Image img = new System.Windows.Controls.Image();
img.Source = new BitmapImage(new Uri(Directory.GetCurrentDirectory() + @"\Resources\Images\immagine1.png"));
I have an exception because the control not find a image.
Can we help me?
I think the error is in the code "Directory.GetCurrentDirectory()"
Upvotes: 1
Views: 84
Reputation: 829
try
System.Windows.Controls.Image img = new System.Windows.Controls.Image();
BitmapImage bm = new BitmapImage(new Uri("@View/Resources/Images/immagine1.png", UriKind.RelativeOrAbsolute));
img.Source = bm;
Upvotes: 0
Reputation: 2267
Directory.GetCurrentDirectory() doesn't give you the path where you are calling from but where your executable is executed from.
http://msdn.microsoft.com/en-us/library/system.io.directory.getcurrentdirectory(v=vs.110).aspx
Upvotes: 1