Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change image source in code behind - Wpf

I need to set image source dynamically, please note my image is in somewhere on the Network, here is my code

BitmapImage logo = new BitmapImage(); logo.BeginInit(); logo.UriSource = new Uri(@"pack://application:,,,\\myserver\\folder1\\Customer Data\\sample.png"); logo.EndInit(); // Getting the exception here ImageViewer1.Source = logo; 

Exception:

The URI prefix is not recognized

like image 469
Muhammad Akhtar Avatar asked Sep 24 '10 12:09

Muhammad Akhtar


2 Answers

None of the above solutions worked for me. But this did:

myImage.Source = new BitmapImage(new Uri(@"/Images/foo.png", UriKind.Relative)); 
like image 112
Manindra Moharana Avatar answered Oct 08 '22 06:10

Manindra Moharana


You just need one line:

ImageViewer1.Source = new BitmapImage(new Uri(@"\myserver\folder1\Customer Data\sample.png")); 
like image 34
timtos Avatar answered Oct 08 '22 07:10

timtos