スマートフォンで一番使うリストビューを解説します。
前回に続いてC#バージョンです。Programmatically
空のプロジェクトを作成します。
モバイルアプリを選択します。
プロジェクト名を指定して作成
空白を選択してOK
MainPage.xaml.csを置き換えます。
MainPage.xaml.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace Xamarin_10
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
var list = new List<string> { "東京", "神田", "お茶の水", "四谷", "新宿", "中野", "荻窪" };
var lv = new ListView() { ItemsSource = list };
lv.ItemTapped += Lv_ItemTapped;
Content = new Xamarin.Forms.ScrollView() { Orientation = ScrollOrientation.Vertical, Content = lv };
}
private void Lv_ItemTapped(object sender, ItemTappedEventArgs e)
{
DisplayAlert("Tapped",$"{e.Item}", "OK");
}
}
}