#275 – Load a Loose Image File into an Image Control

You can distribute an image file as a loose file, i.e. deploy it as a separate file along with your executable, and then load the image into an Image control at runtime.  To do this:

  • Add the image file to your project
  • Set the image file’s Build Action to Content
  • Use a plain filename as the image’s Source
  • Distribute the image file with the executable

Add the image (.png) file to the project.

Set the Build Action to Content.  The image resource won’t be embedded in the .exe file, but the project will know where to find the file.  Also set the Copy to Output Directory field, so that the file is copied.

Use the plain filename as the Source.

<Image Source="TractorSm.png"/>

Distribute the image file along with the executable.  (When you build the project, the file will be automatically copied to the output directory).

Follow

Get every new post delivered to your Inbox.

Join 312 other followers