Permalink
Fetching contributors…
Cannot retrieve contributors at this time
37 lines (33 sloc) 2.02 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
How to: Improve Rendering Performance by Caching an Element
03/30/2017
.net-framework
dotnet-wpf
article
rendering performance [WPF], caching an element
BitmapCache [WPF], improving rendering performance
CacheMode [WPF], improving rendering performance
performance [WPF], caching an element
UIElement [WPF], caching
4739c1fc-60ba-4c46-aba6-f6c1a2688f19
7
dotnet-bot
dotnetcontent
wpickett

How to: Improve Rendering Performance by Caching an Element

Use the xref:System.Windows.Media.BitmapCache class to improve rendering performance of a complex xref:System.Windows.UIElement. To cache an element, create a new instance of the xref:System.Windows.Media.BitmapCache class and assign it to the element's xref:System.Windows.UIElement.CacheMode%2A property. You can reuse a xref:System.Windows.Media.BitmapCache efficiently in a xref:System.Windows.Media.BitmapCacheBrush.

Example

The following code example shows how to create a complex element and cache it as a bitmap, which improves performance when the element is animated. The element is a canvas that holds shape geometries with many vertices. A xref:System.Windows.Media.BitmapCache with default values is assigned to the xref:System.Windows.UIElement.CacheMode%2A of the canvas, and an animation shows the smooth scaling of the cached bitmap.

[!code-xamlSystem.Windows.Media.BitmapCache#_BitmapCacheXAML]

See Also

xref:System.Windows.Media.BitmapCache
xref:System.Windows.Media.BitmapCacheBrush
xref:System.Windows.UIElement.CacheMode%2A
How to: Use a Cached Element as a Brush