#1,110 – Using a Resource as a Content File

When your application needs to use a resource (e.g. an image), it can embed the resource in the executable for the application.  You can then access the resource at run time using a Uri like the one shown below.

BitmapImage bmi = new BitmapImage(new Uri("pack://application:,,,/Ted.jpg"));

You can also include an image in your project and then cause the image to be placed in an output directory along with the executable, but not embedded within it.  You do this by setting its Build Action to Content and by setting the Copy to Output Directory property.


In this case, after building the project, the .jpg file is copied to the output directory.


At run time, you can use exactly the same Uri to access the file, although it is external to the application, rather than embedded.


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #1,110 – Using a Resource as a Content File

  1. Pingback: #1,111 – Referencing Content Files from XAML | 2,000 Things You Should Know About WPF

  2. Pingback: Dew Drop – July 10, 2014 (#1811) | Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: