June 2014 Entries
Setting a WPF Image programmatically

Here is one way to mapping images using code behind in WPF

so.ImgMap.Source = new BitmapImage(new Uri(String.Format("../{0}/{1}",ImagePath,ImageName),UriKind.Relative));
In this example, Images must have their Build Action Property set to Resource or Content and not Embedded Resource in Visual Studio.
image
 
There are many options for the Build Action Property and the help file explains them very well.  For this example, the two that matter are Embedded Resource which is the default and Content.

Content - The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file or in our case where we want to include the file as a default but the user can still reach it if they know how.

Embedded Resource - This file is embedded in the main project build output as a DLL or executable. It is typically used for resource files.

Add Comment Filed Under [ WPF ]