Storing WPF Image Resources

后端 未结 10 1875
眼角桃花
眼角桃花 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:34

    I found to be the best practice of using images, videos, etc. is:

    • Change your files "Build action" to "Content". Be sure to check Copy to build directory.
      • Found on the "Right-Click" menu at the Solution Explorer window.
    • Image Source in the following format:
      • "/«YourAssemblyName»;component/«YourPath»/«YourImage.png»"

    Example

    
    

    Benefits:

    • Files are not embedded into the assembly.
      • The Resource Manager will raise some memory overflow problems with too many resources (at build time).
    • Can be called between assemblies.

提交回复
热议问题