如何通过编程在元素上设置缓存模式?

10

Silverlight 3引入了元素上的CacheMode参数。目前唯一支持的格式是BitmapCache。在XAML中,可以将此值设置为以下内容:

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

我希望在运行时做相同的事情,但迄今为止一直失败,以下两个示例都不起作用。

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

我正在寻求有人能够提供代码或解决方法来动态创建元素(例如Image),并将其CacheMode设置为BitmapCache

1个回答

14

我认为CacheMode属性的值不是枚举类型,而是一个抽象类。

因此,你应该有以下代码:

image.CacheMode = new BitmapCache();

甚至可能在CacheMode等地方有BitmapCache的静态实例。

是的,我认为命名抽象类为~Mode有点奇怪。 ;)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接