Export (0) Print
Expand All

BitmapCache Class

Creates and caches a bitmap representation of a UIElement.

Namespace:  System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public sealed class BitmapCache : CacheMode
<BitmapCache .../>

Use the BitmapCache class to improve rendering performance of a complex UIElement. Create a BitmapCache and assign it to the CacheMode property of a UIElement to cache the element and its subtree as a bitmap in video memory. This is useful when you need to animate, translate, or scale a UIElement as quickly as possible. This approach enables a tradeoff between performance and visual quality while content is cached.

Use the BitmapCacheBrush class to efficiently reuse a cached element.

Set the RenderAtScale property to scale the bitmap cache. This is useful if an element will be zoomed, and you want the element to render more clearly than it would if the cache were simply generated at the element’s native resolution.

Set the SnapsToDevicePixels property when the cache displays content that requires pixel-alignment to render correctly, such as ClearType text. This property is ignored by the BitmapCacheBrush and Viewport2DVisual3D classes.

Caching a control does not affect mouse-over behavior, so mouse-over hit testing operates as if it the bitmap were a live control.

Cache regeneration occurs only when the structure of the UIElement or its subtree changes, or when the CacheMode settings change. Setting the RenderAtScale or EnableClearType properties causes cache regeneration. Changes to the parent visual tree of the cached UIElement, such as transforms, scales, opacities, and effects, do not affect the cache.

The cache functions when hardware acceleration is not available. In this case, the bitmap is rendered in software, and the maximum bitmap dimensions are 2048 x 2048.

NoteNote

RenderOptions and TextOptions do not propagate through a cached element. You may have to set these options again in child elements below the cache.

The following XAML shows how to cache a Canvas element. For the complete code example, see How to: Improve Rendering Performance by Caching an Element.


<!-- //////////////////////////////////////////////////////////////// -->
<!-- // The following XAML creates a BitmapCache with default      // -->
<!-- // properties and assigns it as the CacheMode for the canvas. // -->
<!-- //////////////////////////////////////////////////////////////// -->
<Canvas.CacheMode>
    <BitmapCache EnableClearType="False" 
                 RenderAtScale="1" 
                 SnapsToDevicePixels="False"  />
</Canvas.CacheMode>


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role not supported), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Community Additions

Show:
© 2014 Microsoft