Skip to main content

BitmapCache Class

Definition

Namespace:Avalonia.Media
Assembly:Avalonia.Base
Package:Avalonia

Represents the behavior of caching a visual element or tree of elements as bitmap surfaces.

public class BitmapCache

Inheritance: object -> AvaloniaObject -> Animatable -> StyledElement -> CacheMode -> BitmapCache

Constructors

NameDescription
BitmapCacheNo summary available.

BitmapCache Constructor

public BitmapCache()

Methods

NameDescription
ParseInherited from CacheMode.
ApplyStylingApplies styling to the control if the control is initialized and styling is not already applied. Inherited from StyledElement.
BeginInitInherited from StyledElement.
EndInitInherited from StyledElement.
TryGetResourceInherited from StyledElement.
Bind (8 overloads)Binds a Avalonia.AvaloniaProperty to an Avalonia.Data.BindingBase. Inherited from AvaloniaObject.
CheckAccessReturns a value indicating whether the current thread is the UI thread. Inherited from AvaloniaObject.
ClearValue (4 overloads)Clears a Avalonia.AvaloniaProperty's local value. Inherited from AvaloniaObject.
CoerceValueCoerces the specified Avalonia.AvaloniaProperty. Inherited from AvaloniaObject.
EqualsCompares two objects using reference equality. Inherited from AvaloniaObject.
GetBaseValueInherited from AvaloniaObject.
GetHashCodeGets the hash code for the object. Inherited from AvaloniaObject.
GetValue (3 overloads)Gets a Avalonia.AvaloniaProperty value. Inherited from AvaloniaObject.
IsAnimatingChecks whether a Avalonia.AvaloniaProperty is animating. Inherited from AvaloniaObject.
IsSetChecks whether a Avalonia.AvaloniaProperty is set on this object. Inherited from AvaloniaObject.
SetCurrentValue (2 overloads)Sets the value of a dependency property without changing its value source. Inherited from AvaloniaObject.
SetValue (3 overloads)Sets a Avalonia.AvaloniaProperty value. Inherited from AvaloniaObject.
VerifyAccessChecks that the current thread is the UI thread and throws if not. Inherited from AvaloniaObject.

Properties

NameDescription
EnableClearTypeSet the EnableClearType property to allow subpixel text to be rendered in the cache. When the EnableClearType property is true, your application MUST render all of its subpixel text on an opaque background.
RenderAtScaleUse the RenderAtScale property to render the BitmapCache at a multiple of the normal bitmap size. The normal size is determined by the local size of the element.
SnapsToDevicePixelsSet the SnapsToDevicePixels property when the cache displays content that requires pixel-alignment to render correctly. This is the case for text with subpixel antialiasing. If you set the EnableClearType property to true, consider setting SnapsToDevicePixels to true to ensure proper rendering.
ActualThemeVariantGets the UI theme that is currently used by the element, which might be different than the RequestedThemeVariantProperty. Inherited from StyledElement.
ClassesGets or sets the styled element's classes. Inherited from StyledElement.
DataContextGets or sets the control's data context. Inherited from StyledElement.
IsInitializedGets a value that indicates whether the element has finished initialization. Inherited from StyledElement.
NameGets or sets the name of the styled element. Inherited from StyledElement.
ParentGets the styled element's logical parent. Inherited from StyledElement.
ResourcesGets or sets the styled element's resource dictionary. Inherited from StyledElement.
StyleKeyGets the type by which the element is styled. Inherited from StyledElement.
StylesGets the styles for the styled element. Inherited from StyledElement.
TemplatedParentGets the styled element whose lookless template this styled element is part of. Inherited from StyledElement.
ThemeGets or sets the theme to be applied to the element. Inherited from StyledElement.
TransitionsGets or sets the property transitions for the control. Inherited from Animatable.
DispatcherReturns the Avalonia.AvaloniaObject.Dispatcher that this Avalonia.AvaloniaObject is associated with. Inherited from AvaloniaObject.
ItemInherited from AvaloniaObject.

EnableClearType Property

Set the EnableClearType property to allow subpixel text to be rendered in the cache. When the EnableClearType property is true, your application MUST render all of its subpixel text on an opaque background.

When the EnableClearType property is false, text in the cache is rendered with grayscale antialiasing.

ClearType text requires correct pixel alignment of rendered characters, so you should set the SnapsToDevicePixels property to true. If you do not set this property, the content may not blend correctly.

Use the EnableClearType property when you know the cache is rendered on pixel boundaries, so it is safe to cache ClearType text. This situation occurs commonly in text-scrolling scenarios.

public bool EnableClearType { get; set; }

RenderAtScale Property

Use the RenderAtScale property to render the BitmapCache at a multiple of the normal bitmap size. The normal size is determined by the local size of the element.

Values greater than 1 increase the resolution of the bitmap relative to the native resolution of the element, and values less than 1 decrease the resolution. For example, if the RenderAtScale property is set to 2.0, and you apply a scale transform that enlarges the content by a factor of 2, the content will have the same visual quality as the same content with RenderAtScale set to 1.0 and a transform scale of 1.

When RenderAtScale is set to 0, no bitmap is rendered. Negative values are clamped to 0.

If you change this value, the cache is regenerated at the appropriate new resolution.

public double RenderAtScale { get; set; }

SnapsToDevicePixels Property

Set the SnapsToDevicePixels property when the cache displays content that requires pixel-alignment to render correctly. This is the case for text with subpixel antialiasing. If you set the EnableClearType property to true, consider setting SnapsToDevicePixels to true to ensure proper rendering.

When the SnapsToDevicePixels property is set to false, you can move and scale the cached element by a fraction of a pixel.

When the SnapsToDevicePixels property is set to true, the bitmap cache is aligned with pixel boundaries of the destination. If you move or scale the cached element by a fraction of a pixel, the bitmap snaps to the pixel grid . In this case, the top-left corner of the bitmap is rounded up and snapped to the pixel grid, but the bottom-right corner is on a fractional pixel boundary.

public bool SnapsToDevicePixels { get; set; }

Fields

NameDescription
EnableClearTypePropertyNo summary available.
RenderAtScalePropertyNo summary available.
SnapsToDevicePixelsPropertyNo summary available.
DataContextPropertyDefines the Avalonia.StyledElement.DataContext property. Inherited from StyledElement.
NamePropertyDefines the Avalonia.StyledElement.Name property. Inherited from StyledElement.
ParentPropertyDefines the Avalonia.StyledElement.Parent property. Inherited from StyledElement.
TemplatedParentPropertyDefines the Avalonia.StyledElement.TemplatedParent property. Inherited from StyledElement.
ThemePropertyDefines the Avalonia.StyledElement.Theme property. Inherited from StyledElement.
TransitionsPropertyDefines the Avalonia.Animation.Animatable.Transitions property. Inherited from Animatable.

EnableClearTypeProperty Field

public Avalonia.StyledProperty<TValue><bool> EnableClearTypeProperty

RenderAtScaleProperty Field

public Avalonia.StyledProperty<TValue><double> RenderAtScaleProperty

SnapsToDevicePixelsProperty Field

public Avalonia.StyledProperty<TValue><bool> SnapsToDevicePixelsProperty

Events

NameDescription
ActualThemeVariantChangedRaised when the theme variant is changed on the element or an ancestor of the element. Inherited from StyledElement.
AttachedToLogicalTreeRaised when the styled element is attached to a rooted logical tree. Inherited from StyledElement.
DataContextChangedOccurs when the Avalonia.StyledElement.DataContext property changes. Inherited from StyledElement.
DetachedFromLogicalTreeRaised when the styled element is detached from a rooted logical tree. Inherited from StyledElement.
InitializedOccurs when the styled element has finished initialization. Inherited from StyledElement.
ResourcesChangedOccurs when a resource in this styled element or a parent styled element has changed. Inherited from StyledElement.
PropertyChangedRaised when a Avalonia.AvaloniaProperty value changes on this object. Inherited from AvaloniaObject.