我讀過為了提高性能,如果它與布局的默認值相同,則不應在布局中設定屬性的值。作為一個簡單的例子,如果我有一個StackLayout并且我希望它垂直定向,我可能會寫
<StackLayout
Orientation="Vertical"
>
</StackLayout>
但我從經驗中知道這Vertical是 StackLayout 的默認方向,因此設定這個值是多余的,會降低性能。
我不知道是許多其他屬性,如默認值Padding,Margin,HorizontalOptions,VerticalOptions和其他一切,并為其他布局等Grid。
有沒有更簡單的方法來找到這些值,以避免在設定和不設定值的情況下嘗試每個布局?
uj5u.com熱心網友回復:
你會發現 Xamarin 檔案或它的 API 檔案中提到了它,例如:
- Horizo??ntalOptions/VerticalOptions:默認值為
LayoutOptions.Fill。 - 填充:默認值為
Thickness0 值的型別。
如果檔案中沒有提到,可以查看源代碼;:
HorizontalOptions, VerticalOptions, MarginareView的屬性,您將在View.cs 中找到它們的宣告。因為
StackLayout.Spacing你會在StackLayout.cs等中找到它。
uj5u.com熱心網友回復:
您也可以雙擊StackLayoutXaml 中的 來選擇它。然后在鍵盤上按F12。它將打開 StackLayout 的元資料。
在 的注釋中Orientation,value 部分將顯示默認值。
//
// 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.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/402161.html
標籤:xaml 沙马林 xamarin.forms 布局 特性
下一篇:將API回應列印到列
