發表文章

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

[Xamarin]建立自訂的 Resource Dictionary 檔案

圖片
介紹如何在 Xamarin 中建立自訂的 Resource Dictionary (資源字典) 檔案。 最近受到  James Tsai  的感召,開始著手小玩一下 Xamarin.Forms,記得在寫 WPF/UWP 的時候自己常常要自訂一些 Resource Dictionary 檔案,於是小小研究了一下在 Xamarin.Forms 中如何完成這樣的需求。 在 UWP 中我們要新增個 Resource Dictionary 檔案很容易,只要加入新增項目,選擇資源字典就可以了。 接著我們在 Dictionary1.xaml 中設計一個簡單的 Style < ResourceDictionary xmlns = " http://schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:x = " http://schemas.microsoft.com/winfx/2006/xaml " xmlns:local = "using:App2" > < Style x:Key = "myTextBlockStyle" TargetType = "TextBlock" > < Setter Property =" Foreground " Value =" Red "/> </ Style > </ ResourceDictionary > 接著我們可以在其他的 xaml code 中利用 ResourceDictionary.MergedDictionaries 引用這個 Resource Dictionary   < Page x:Class = "App2.MainPage" xmlns = " http://schemas.microsoft.com/winfx/2006/xaml/presentation " xmlns:...

[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 ...