I've read that to increase performance you shouldn't set the value of a property within a layout if it's the same as the default value for a layout. As a simple example, if I had a StackLayout
and I wanted it to be oriented vertically, I might write
<StackLayout
Orientation="Vertical"
>
</StackLayout>
but I know from experience that Vertical
is the default orientation for a StackLayout and thus setting this value is redundant and will reduce performance.
What I don't know is the default value for many other properties such as Padding
, Margin
, HorizontalOptions
, VerticalOptions
and everything else, and for other layouts such as Grid
.
Is there a simpler way to find these values that avoids trialing each layout with and without setting the values?
CodePudding user response:
You will find it mentioned in the Xamarin documentation or it API documentation, for instance:
- HorizontalOptions/VerticalOptions : default value is
LayoutOptions.Fill
. - Padding : default is a
Thickness
type of 0 values.
If not mentioned in the documentation, you can look at the source code;:
HorizontalOptions, VerticalOptions, Margin
areView
's properties you will find their declaration in View.cs.For
StackLayout.Spacing
you will find it in StackLayout.cs and so on.
CodePudding user response:
You could also double click the StackLayout
in the Xaml to choose it. And then press F12 on keyboard. It would open a metadata for StackLayout.
In the comment of Orientation
, the part of value would show the default.
//
// Summary:
// Gets or sets the value which indicates the direction which child elements are
// positioned.
//
// Value:
// A Xamarin.Forms.StackOrientation which indicates the direction children layouts
// flow. The default value is Vertical.
//
// Remarks:
// Setting the Orientation of a StackLayout triggers a layout cycle if the stack
// is already inside of a parent layout. To prevent wasted layout cycles, set the
// orientation prior to adding the StackLayout to a parent.