One of the cool things coming in the 2.5 release of Xamarin Forms is something called Layout Compression. If you have done any kind of Xaml work whether with Xamarin Forms or WPF or even Silverlight, you know that end up with multiple levels of nested containers before finally reaching content.
Demo : https://github.com/jsuarezruiz/layout-compression-sample
All of these elements have to be recursed through to determine the measurements and the layouts and this can take time, especially when you start to consider wrappers for platform renderers, list/tree view item templates to name a few.
In 2.5, you can tell Xamarin Forms which views can be opted out of rendering to speed up your UI, simply by adding the ‘CompressedLayout.IsHeadless=”True”‘ to your Layout.
1 2 3 | < StackLayout CompressedLayout.IsHeadless = "true" > </ StackLayout > |
Using C#
CompressedLayout.SetIsHeadless(stackLayout, true);
Since layout compression removes a layout from the visual tree, it's not suitable for layouts that have a visual appearance, or that obtain touch input. Therefore, layouts that set VisualElement
properties (such as BackgroundColor
, IsVisible
, Rotation
, Scale
, TranslationX
and TranslationY
or that accept gestures, are not candidates for layout compression. However, enabling layout compression on a layout that sets visual appearance properties, or that accepts gestures, will not result in a build or runtime error. Instead, layout compression will be applied and visual appearance properties, and gesture recognition, will silently fail.
It’s important to remember that anything you expected to be part of the layout will be gone, things such as the background color, gestures etc. So be careful what you compress!
No comments:
Post a Comment