發表文章

目前顯示的是有「LayoutOptions」標籤的文章

[Xamarin.Forms] 筆記 LayoutOptions 的 Expands

圖片
這只是一則小筆記,紀錄 Xamarin.Forms LayoutOptions structure 中 Expands Property 對於布局的影響。 最近在練 Xamrin.Forms,遇到甚麼 StartAndExpand、CenterAndExpand 和 EndAndExpand 時很容易犯糊塗,寫的文章記錄一下。 LayoutOptions Structure 在 Xamarin Forms 上排版的時候經常使用到工具中其中有兩個是 View Class 的  VerticalOptions  和  HorizontalOptions ,這兩個屬性的型別都是  LayoutOptions ;這個結構的公開成員只有兩個屬性 : Alignment :這個屬性描述的是這個 View 物件如何對齊,型別是 LayoutAlignment 列舉 ,內容只有 Center、End、Fill 與 Start。 Expands:這個屬性值是個  bool 型別,表明有沒有擴展行為而已。像是 CenterAndExpand 這個靜態欄位的 Expands 屬性值就是 true。 一般我們常用在 XAML code 裡面的那些甚麼 Start、End 還是 StartAndExpand 等等的玩意,其實都是 LayoutOptions 的靜態欄位 (型別也是 LayoutOptions)。這些靜態欄位的內容其實就是前述兩個屬性的變化而已。 Expands 雖然對於其他種類 (如 WPF、UWP 等等) 的 XAML 算來是挺熟,但講起 Xamarin Forms 的 XAML 就沒有這種熟悉度了,像是 StartAndExpand、CenterAndExpand 這一類的對齊方式一直讓我很好奇,同時也一直有點模糊。後來發現一件事,如果要類比這些 Expands 為 true 的行為,最接近的說法就是在 Grid 裡面用 * 標示的 Row Height 或 Column Width,也就是說這些 Expands 為 true 的 view 在 StackLayout 中會均分剩下的空間。 這邊使用一個簡單的 XAML Code 來展現 Expands ...