Store Images as Resources into ResourceDictionary in WPF

The point of this is all the elements, which have this image on it, will be at the same time updated once this image source is changed to refer to another image. It is a centralized way to manage all the images. Do it as followling:

Add “ImageSource” entry in a ResourceDictionary.

<ImageSource x:Key=”someImage”>Images/SomeImage.extension</ImageSource>

P.S.

Strongly recommended to put all the images in one folder called “Images” under the main project folder.

About these ads

~ by Martin on August 13, 2007.

6 Responses to “Store Images as Resources into ResourceDictionary in WPF”

  1. You saved my night,My wife wish to you best wishes. ;)

  2. Super nice idea. Thx Alex

  3. Ahh.. ImageSource! Thanks!

  4. I have been experimenting with putting the resouces in an external library, images included but when I reference the external resource

    The images that are in the Skin.dll as resources are not visible to the WPF application that is referencing the Skin.dll Do you know why the WPF app is unable to get to the images in the Skin.dll?

    • Probably specifying full Uri for ImageSource can solve that, for example:
      /Skin;component/Images/SomeImage.extension

  5. Good work Martin!

    This opens teh door to a lot of possibilities.
    You helped me realise that ANY object can be placed in a ResourceDictionary

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: