Permalink
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (32 sloc) 1.83 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: Use a Cached Element as a Brush
03/30/2017
.net-framework
dotnet-wpf
article
BitmapCache [WPF], using
cached element [WPF], use as a brush
BitmapCacheBrush [WPF], using
CacheMode [WPF], using
d36e944a-866e-4baf-98c4-fd6a75f6fdd0
5
dotnet-bot
dotnetcontent
wpickett

How to: Use a Cached Element as a Brush

Use the xref:System.Windows.Media.BitmapCacheBrush class to reuse a cached element efficiently. 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.

Example

The following code example shows how to reuse a cached element. The cached element is an xref:System.Windows.Controls.Image control that displays a large image. The xref:System.Windows.Controls.Image control is cached as a bitmap by using the xref:System.Windows.Media.BitmapCache class, and the cache is reused by assigning it to a xref:System.Windows.Media.BitmapCacheBrush. The brush is assigned to the background of twenty-five buttons to show efficient reuse.

[!code-xamlSystem.Windows.Media.BitmapCacheBrush#_BitmapCacheBrushXAML]

See Also

xref:System.Windows.Media.BitmapCache
xref:System.Windows.Media.BitmapCacheBrush
xref:System.Windows.UIElement.CacheMode%2A
How to: Improve Rendering Performance by Caching an Element