Tuesday, August 27, 2019

Loading an image into an ImageButton from an EmbeddedResource

Sad, but this took me awhile to figure out.  A lot of the examples on the web are incorrect so it took quite a bit of thrashing to figure this simple thing out.

The way to load an image into an ImageButton from an EmbeddedResource is to of course add an image to your project and mark it as EmbeddedResource. 

The next step is to determine the “path” to this resource.  If the project name is “Project” and the folder you added your image to is named “Folder” and the image is named “Image.png” then the “path” to this image is "Project.Folder.Image.png”

Then it is a simple process to use the static class ImageSource, like this:

ImageSource.FromResource("Project.Folder.Image.png")

No comments: