Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework
BitmapImage Class
 CacheOption Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
BitmapImage..::.CacheOption Property

Gets or sets the BitmapCacheOption to use for this instance of BitmapImage. This is a dependency property.

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

Visual Basic (Declaration)
Public Property CacheOption As BitmapCacheOption
Visual Basic (Usage)
Dim instance As BitmapImage
Dim value As BitmapCacheOption

value = instance.CacheOption

instance.CacheOption = value
C#
public BitmapCacheOption CacheOption { get; set; }
Visual C++
public:
property BitmapCacheOption CacheOption {
    BitmapCacheOption get ();
    void set (BitmapCacheOption value);
}
J#
/** @property */
public BitmapCacheOption get_CacheOption()
/** @property */
public  void set_CacheOption(BitmapCacheOption value)
JScript
public function get CacheOption () : BitmapCacheOption
public function set CacheOption (value : BitmapCacheOption)
XAML Attribute Usage
<object CacheOption="BitmapCacheOption" .../>

Property Value

Type: System.Windows.Media.Imaging..::.BitmapCacheOption

The BitmapCacheOption being used for the BitmapImage. The default is BitmapCacheOption..::.Default.

Identifier field

CacheOptionProperty

Metadata properties set to true

None

Set the CacheOption to BitmapCacheOption..::.OnLoad if you wish to close a stream used to create the BitmapImage. The default OnDemand cache option retains access to the stream until the image is needed, and cleanup is handled by the garbage collector.

The following code example demonstrates how to set the CacheOption of a BitmapImage by using code.

C#
// Define a BitmapImage.
Image myImage = new Image();
BitmapImage bi = new BitmapImage();

// Begin initialization.
bi.BeginInit();

// Set properties.
bi.CacheOption = BitmapCacheOption.OnDemand;
bi.CreateOptions = BitmapCreateOptions.DelayCreation;
bi.DecodePixelHeight = 125;
bi.DecodePixelWidth = 125;
bi.Rotation = Rotation.Rotate90;
MessageBox.Show(bi.IsDownloading.ToString());
bi.UriSource = new Uri("smiley.png", UriKind.Relative);

// End initialization.
bi.EndInit();
myImage.Source = bi;
myImage.Stretch = Stretch.None;
myImage.Margin = new Thickness(5);

Visual Basic
' Define a BitmapImage.
Dim myImage As New Image()
Dim bi As New BitmapImage()

' Begin initialization.
bi.BeginInit()

' Set properties.
bi.CacheOption = BitmapCacheOption.OnDemand
bi.CreateOptions = BitmapCreateOptions.DelayCreation
bi.DecodePixelHeight = 125
bi.DecodePixelWidth = 125
bi.Rotation = Rotation.Rotate90
MessageBox.Show(bi.IsDownloading.ToString())
bi.UriSource = New Uri("smiley.png", UriKind.Relative)

' End initialization.
bi.EndInit()
myImage.Source = bi
myImage.Stretch = Stretch.None
myImage.Margin = New Thickness(5)

Windows Vista

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

.NET Framework

Supported in: 3.5, 3.0 SP1, 3.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content      
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker