Performance and Element Visibility

,

XAML-based apps provide two properties that allow you to hide or reveal UI elements: UIElement.Visibility and UIElement.Opacity—each of which has performance implications depending on how it is used.

The UIElement.Visibility property is handled by the UI thread. When an element’s Visibility property is set to Collapsed, the visual tree must be redrawn. The upside is that when collapsed, the UIElement is not retained in visual memory, and thus decreases the amount of memory used by your app.

Conversely, controlling the visibility of an element using the UIElement.Opacity property allows the element to be bitmap cached; the element is stored as a simple bitmap image after the first render pass. Bitmap caching allows the rendering system to bypass the render phase for the cached element and to use the composition thread to display the bitmap instead, which can free up the UI thread considerably. By setting the opacity of a cached element to zero, you hide the element without requiring it to be redrawn later. This, however, does mean that unlike the Visibility property, the element is still retained in visual memory.


Note

Avoid manipulating the UIElement.Opacity property without enabling bitmap caching. Set the UIElement.CacheMode property to BitmapCache, as shown in the following example:

<Path CacheMode="BitmapCache" ... />


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.36.174