Files
docs-desktop/dotnet-desktop-guide/framework/wpf/graphics-multimedia/how-to-use-a-cached-element-as-a-brush.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

25 lines
1.5 KiB
Markdown

---
title: "How to: Use a Cached Element as a Brush"
ms.date: "03/30/2017"
helpviewer_keywords:
- "BitmapCache [WPF], using"
- "cached element [WPF], use as a brush"
- "BitmapCacheBrush [WPF], using"
- "CacheMode [WPF], using"
ms.assetid: d36e944a-866e-4baf-98c4-fd6a75f6fdd0
---
# 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-xaml[System.Windows.Media.BitmapCacheBrush#_BitmapCacheBrushXAML](~/samples/snippets/csharp/VS_Snippets_Wpf/system.windows.media.bitmapcachebrush/cs/window1.xaml#_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](how-to-improve-rendering-performance-by-caching-an-element.md)