Comment on page
Performance
As you get comfortable with XAML you'll start to see the power of what you can achieve. With this power comes the responsibility to understand the performance implications of your actions. Each view (Grids, StackLayouts, Labels, etc.) adds overhead to the page as it is rendered. You'll want to make sure you limit how many views you add.
The most important aspect of layout-level optimization is knowing when you should be using which layout. As a XAML developer, you should be aware of how each of these layouts work and what the drawbacks are of using each of them.

- Don't set the
VerticalOptions
andHorizontalOptions
properties of a layout unless required. The default values ofLayoutOptions.Fill
andLayoutOptions.FillAndExpand
allow for the best layout optimization. Changing these properties has a cost and consumes memory, even when setting them to the default values. - Avoid deeply nested layout hierarchies. Use
AbsoluteLayout
orGrid
to help reduce nesting. - Prefer animating views with the
TranslationX
andTranslationY
properties as this avoids the need for layout. - Bypass transparency — if you can achieve the same (or close enough) effect with full opacity, do so.
- Don't use a
StackLayout
to host a single child. Instead, use theContentView
layout. - Don't use multiple
StackLayout
s when aGrid
suffices. - Don't use multiple
StackLayout
s to simulate aGrid
. - Don't use a
StackLayout
inside aScrollView
to simulate aListView
. - Don't set more than one child to
LayoutOptions.Expands
. This property ensures that the specified child will occupy the largest space that theStackLayout
can give to it, and it is wasteful to perform these calculations more than once.
- Avoid using the
AbsoluteLayout.AutoSize
property whenever possible.