WPF – Import image as resource

  • 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 the XAML Parser.

In code behind, you would write

bitmap.UriSource = new Uri("pack://application:,,,/images/jamsnaps-dark.png");

Leave a Comment