Cached Image

A WPF control that wraps the Image control to enable file-system based caching.

View the Project on GitHub floydpink/CachedImage


CachedImage NuGet version Build status

A WPF control that wraps the Image control to enable file-system based caching.


If we use the native WPF Image control for displaying images over the HTTP protocol (by setting the Source to an http url), the image will be downloaded from the server every time the control is loaded.

In its Dedicated mode (see Cache Mode below), the Image control present in this CachedImage library, wraps the native Image control to add a local file-system based caching capability. This control creates a local copy of the image on the first time an image is downloaded; to a configurable cache folder (defaults to <current-user/appdata/roaming>\AppName\Cache). All the subsequent loads of the control (or the page, window or app that contains the control), will display the image from the local file-system and will not download it from the server.

In its WinINet mode, the Image control uses the Temporary Internet Files directory that IE uses for the cache.

Cache Mode

We provide two cache mode: WinINet mode and Dedicated mode.


  1. Install the NuGet package named CachedImage on the WPF project
  2. Add a namespace reference to the CachedImage assembly on the Window/Usercontrol xmlns:cachedImage="clr-namespace:CachedImage;assembly=CachedImage" as in the example Window below:

    <Window x:Class="MyWindow1"
  3. Use the control and set or bind the ImageUrl attribute:

        <cachedImage:Image ImageUrl="{Binding LargeImageUrl}">  </cachedImage:Image>
  4. As it is only a wrapper, all the XAML elements that could be used with the Image control are valid here as well:

      <cachedImage:Image ImageUrl="{Binding LargeImageUrl}">
          <Image.ToolTip>This image gets cached to the file-system the first time it is downloaded</Image.ToolTip>
  5. To change cache mode, set FileCache.AppCacheMode like this:

      CachedImage.FileCache.AppCacheMode = CachedImage.FileCache.CacheMode.Dedicated; // The default mode is WinINet
  6. To change the cache folder location of the dedicated cache mode, set the static string property named AppCacheDirectory of the FileCache class like this:

      CachedImage.FileCache.AppCacheDirectory = string.format("{0}\\MyCustomCacheFolder\\",
  7. Please note that the dedicated cache mode does not consider Cache-Control or Expires headers. Unless the cache folder (or specific files in it) gets deleted, the control will not fetch the file again from the server. The application could let the end-user empty the cache folder as done in the flickr downloadr application that uses this control.


All of the code in this library is from the answers on a Stack Overflow question:

How do I cache images on the client for a WPF application?.

Thanks to:

  1. Simon Hartcher, who answered his own question with the solution

  2. Jeroen van Langen for the wonderful refacoring of Simon's solution

  3. Ivan Leonenko for the tweaks to make the control bindable.

  4. Aybe for the fix for non-ascii characters in the path (#1)

  5. Saiqi Jia for the enhancement of adding another IE based caching (#5)


MIT License