Xamarin.Forms<一>

來源:互聯網
上載者:User

標籤:

  Xamarin這一新鮮玩意,讓好多C#開發人員看到了開發IOS和Android的希望,我們就滿懷希望的用上了這新鮮
玩意,不過Xamarin就如美麗的月球一樣,滿滿的都是坑~。廢話不多了,先從View層的控制項開始,也主要是我負責
的View層,一點點摸索過來的,不過肯定會有瑕疵。

各個控制項View
ActivityIndicator
滾動的圓圈,表示後台有進行的運算。主要屬性,IsRunning。
BoxView
一個有顏色的矩形,可以用於分割線。
Button
按鈕,主要屬性Image,Click。
View Code
DatePicker
日期控制項,字型顏色預設無法設定。binding的屬性為DateTime。
Editor
長文本控制項,可以斷行符號換行,字型顏色預設無法設定
Entry
短文本控制項,不可斷行符號換行
Image
圖片控制項,包括程式圖片、本地圖片以及網狀圖片
Label

標籤,文本顯示
ListView
列表

 1 public class TestPage : ContentPage 2     { 3         public TestPage() 4         { 5             this.BindingContext = new TestModel(); 6         } 7  8         public ListView TestListView() 9         {10             var testList = new ListView11             {12                 HasUnevenRows = true,13                 //RowHeight = 40,14             };15             testList.ItemTemplate = new DataTemplate(typeof(TestViewCell));16             testList.SetBinding(ListView.ItemsSourceProperty, "TestList");17             testList.SetBinding(ListView.SelectedItemProperty, "SelectedTest");18             return testList;19         }20     }21 22     /// <summary>23     /// 測試清單選項類24     /// </summary>25     public class TestViewCell : ViewCell26     {27         public TestViewCell()28         {29             this.View = null;30         }31 32         public StackLayout TestViewCellSL()33         {34             var textName = new Label35             {36             };37             textName.SetBinding(Label.TextProperty, "TestName");38             var textImage = new Image39             {40             };41             textImage.SetBinding(Image.SourceProperty, "ImageSource");42             var testViewCellSL = new StackLayout43             {44                 Orientation = StackOrientation.Horizontal,45                 Children =46                 {47                     textImage,48                     textName,49                 },50             };51             return testViewCellSL;52         }53     }54 55     /// <summary>56     /// 測試類別57     /// </summary>58     public class TestClass59     {60         public TestClass()61         {62         }63 64         public string TestName {  set; get; }65 66         public string ImageSource {  set; get; }67     }68 69     /// <summary>70     /// 測試Model71     /// </summary>72     public class TestModel73     {74         public TestModel()75         {76             TestList.Add(new TestClass { TestName = "1", ImageSource = "1.jpg" });77             TestList.Add(new TestClass { TestName = "2", ImageSource = "2.jpg" });78             TestList.Add(new TestClass { TestName = "3", ImageSource = "3.jpg" });79             TestList.Add(new TestClass { TestName = "4", ImageSource = "4.jpg" });80             TestList.Add(new TestClass { TestName = "5", ImageSource = "5.jpg" });81             TestList.Add(new TestClass { TestName = "6", ImageSource = "6.jpg" });82             TestList.Add(new TestClass { TestName = "7", ImageSource = "7.jpg" });83         }84         public List<TestClass> TestList = new List<TestClass>();85 86         public TestClass SelectedTest { get; set; }87     }
View Code

OpenGLView
Picker
相當於單選,從一個List裡面選擇一項,沒有source屬性binding,選項只能是純文字,並且選擇的是
index,index從0開始,這個比較噁心,綁定SelectedIndex的時候有點費事。主要事件:SelectedIndexChanged。
ProgressBar
進度條,主要屬性ProgressProperty,0至1。
SearchBar
搜尋欄,字型顏色預設無法設定。主要事件:SearchButtonPressed。
Slider
線性控制欄,調節音量或亮度可用的控制項。主要屬性:Minimum最小值,Maximum最大值。主要事件:
ValueChanged。
Stepper
加減號按鈕控制器,通過按鈕控制變化的控制項。主要屬性:Minimum最小值,Maximum最大值,Increment
每次增加值。主要事件:ValueChanged。
Switch
切換器,類似於Check控制項,Xamarin.Form沒有Check控制項。只要事件:Toggled。
TableView
一個可以包含多個Cell的控制項,類似於ListView,不過這的每行的控制項可以不一致。
TimePicker
時間控制項,24小時。binding的屬性為TimeSpan。
WebView
網頁控制項,主要屬性Source = newUrlWebViewSource {Url = "http://baidu.com"}
官方網址:http://developer.xamarin.com/guides/cross-platform/xamarin-forms/controls/views/

Xamarin.Forms<一>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.