Storing WPF Image Resources

后端 未结 10 2060
眼角桃花
眼角桃花 2020-11-22 11:17

For a WPF application which will need 10 - 20 small icons and images for illustrative purposes, is storing these in the assembly as embedded resources the right way to go?

10条回答
  •  再見小時候
    2020-11-22 11:37

    If you will use the image in multiple places, then it's worth loading the image data only once into memory and then sharing it between all Image elements.

    To do this, create a BitmapSource as a resource somewhere:

    
    

    Then, in your code, use something like:

    
    

    In my case, I found that I had to set the Image.png file to have a build action of Resource rather than just Content. This causes the image to be carried within your compiled assembly.

提交回复
热议问题