WPF - Import image as resource

后端 未结 3 941
醉梦人生
醉梦人生 2020-11-22 06:42

In WinForms it is possible to import an image as a resource, and the image would still work when compiled in the /bin/Debug folder.

I can\'t figure out how to get t

3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 07:12

    • Create a folder (e.g. images) in your Visual Studio Project.
    • Add the image file(s) to that folder.
    • Set their Build Action to Resource (in the Properties window, see second image in this answer).

    Then write the UriSource property like you already did:

    UriSource="/images/jamsnaps-dark.png"
    

    That URI is effectively a Resource File Pack URI, where the prefix is automatically added by WPF.

提交回复
热议问题