My motivation for this question is really just to specify an image to be used in a user control via a dependency property for ImageSource. I'm hitting some pain points involving the management, access, and unit testing for this.
- Is the resource editor a good tool to use to maintain images for the application?
- What is the best way to translate the Bitmap from the editor to an ImageSource?
- How can I grab the resource Filename from the editor?
No, the resource editor is not a good tool for this.
In a WPF application the best way is to put all of your images in an "Images" directory and mark each one as a "Resource". Then you can reference them directly in Image controls and elsewhere.
Here are the precise steps:
Now you can reference your images easily in XAML:
Or in code:
You can also reference images in external assemblies:
Which in code would be: