10

Silverlight 3 introduced the CacheMode parameter on elements. Currently the only supported format is BitmapCache. In XAML this value can set as the following:

<Image CacheMode="BitmapCache" Source="MyImage.png"></Image>

I would like to do the same thing at runtime but have failed so far, neither of the following examples work

Image image;
image.CacheMode = ?? // Could not find any enum to set it to
image.CacheMode.SetValue(CacheModeProperty, "BitmapCache"); // Does not work

I'm looking for someone to provide code or workaround for dynamically creating an element (e.g. Image) and setting its CacheMode to BitmapCache.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Gergely Orosz
  • 6,475
  • 4
  • 47
  • 59

1 Answers1

14

I don't think the property value of CacheMode is an enum, I think its an abstract class.

So you should have something like:

image.CacheMode = new BitmapCache();

There might even be a static instance of BitmapCache somewhere (like on CacheMode).

And yes, having an abstract class called ~Mode is a bit weird imo ;)

meandmycode
  • 17,067
  • 9
  • 48
  • 42