Xamarinを少し触り始めたので。サンプル色々。
ボタンでアラート
1 2 3 4 5 6 7 8 9 |
var button = new Button() { Text = "BUTTON" }; button.Clicked += async (sender, e) => { var result = await DisplayAlert("タイトル", "本文", "YES", "NO"); }; Content = button; |
ピッカー(選択リスト)
1 2 3 4 5 6 7 8 9 10 11 |
var piker = new Picker { Title = "選択", VerticalOptions = LayoutOptions.Start }; var ar = Enumerable.Range(0, 100).Select(n => string.Format("item{00}", n)); foreach (var a in ar) { piker.Items.Add(a); } Content = piker; |
タイマーとプログレスバー
1 2 3 4 5 6 7 8 9 10 11 12 |
var pbar = new ProgressBar { WidthRequest = 300, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.CenterAndExpand }; Device.StartTimer(TimeSpan.FromSeconds(0.1), () => { pbar.Progress += 0.01; return pbar.Progress != 1; }); Content = pbar; |
サーチバー(インプットボックス)
1 2 3 4 5 6 7 8 9 10 11 |
var sbar = new SearchBar { Placeholder = "input", VerticalOptions = LayoutOptions.Start }; sbar.SearchButtonPressed += (s, e) => { DisplayAlert("入力!", sbar.Text, "ClickMe!"); }; Content = sbar; |
リストビュー
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
ListView listView = new ListView { ItemsSource = Enumerable.Range(1, 10).Select(x => string.Format("No{00}", x)).ToList() }; //アタッチ listView.ItemSelected += new EventHandler<SelectedItemChangedEventArgs>((object sender, SelectedItemChangedEventArgs e) => { }); //アタッチ簡略 listView.ItemSelected += (s, e) => { DisplayAlert("", ((ListView)s).SelectedItem.ToString(), "OK"); }; Content = listView; |