I have an image lock.png
beside of my WPF exe file in the images
folder.
Now, I'm gonna load it into the WPF Project as an image, I've used the following XAML code:
<Image Stretch="Fill" Source="pack://siteoforigin:,,,/images/lock.png" />
It works, but Expression Blend
or Visual Studio
doesn't show it when I'm working on the project.
How can we show external images in these situations?
Try to load your image dynamically. This should be on xaml:
<Image Stretch="Fill" Name="MyImage" />
And this in code behind. On Window_Loaded or in Window constructor:
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "images/lock.png"))
{
Uri uri = new Uri(AppDomain.CurrentDomain.BaseDirectory + "images/lock.png", UriKind.RelativeOrAbsolute);
MyImage.Source = BitmapFrame.Create(uri);
}