UIElement.CacheMode Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets or sets a value that indicates that rendered content should be cached when possible.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Property CacheMode As CacheMode
public CacheMode CacheMode { get; set; }
<uiElement>
  <uiElement.CacheMode>
    singleBitmapCache
  </uiElement.CacheMode>
</uiElement>

XAML Values

  • singleBitmapCache
    Exactly one BitmapCache object element, generally with the RenderAtScale attribute set. Technically, the XAML accepts any CacheMode object value, but BitmapCache is the only existing practical derived class in the Silverlight core API.

Property Value

Type: System.Windows.Media.CacheMode
A value that indicates that rendered content should be cached when possible. If you specify a value of CacheMode, rendering operations from RenderTransform and Opacity execute on the graphics processing unit (GPU), if available. The default is nulla null reference (Nothing in Visual Basic), which does not enable a cached composition mode.

Remarks

Dependency property identifier field: CacheModeProperty

In order to enable caching, you must enable composition caching at the plug-in level by setting the value of an EnableGPUAccelerationparam element to true as part of the object tag that declares the Silverlight plug-in.

To use GPU hardware acceleration in Silverlight effectively, you should understand how Silverlight uses hardware acceleration and cached composition in its architecture, and which Silverlight objects and rendering scenarios can benefit under hardware acceleration. For more information, see Silverlight Hardware Acceleration.

You can profile hardware acceleration optimizations in the development phase of your application; see EnableCacheVisualization (Silverlight Plug-in Object).

The XAML usage shown is the only practical available usage in Silverlight core libraries. In theory, other CacheMode classes could be written to fill the CacheMode value, but these would be custom classes. See BitmapCache for the attributes you might set on the BitmapCache object element value.

NoteNote:

Out-of-browser applications do not have editable hosting HTML. To enable GPU acceleration for an out-of-browser application, set the attribute EnableGPUAcceleration to true on the OutOfBrowserSettings element that you declare in your Deployment XAML file.

Version Notes

Silverlight for Windows Phone Silverlight for Windows Phone

Silverlight for Windows Phone has a different set of operations that can use GPU acceleration; for more information, see Graphics in Silverlight for Windows Phone.

Examples

Before you can use the CacheMode property, you need to enable GPU acceleration at the plug-in level (in the HTML) by setting the EnableGPUAcceleration parameter to true.

<param name="EnableGPUAcceleration" value="true" />

The following XAML uses a BitmapCache to set CacheMode for a MediaElement.

<MediaElement>
  <MediaElement.CacheMode>
    <BitmapCache RenderAtScale="4"/>
  </ MediaElement.CacheMode>
</MediaElement>

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.