Skip to content

Instantly share code, notes, and snippets.

@ytabuchi
Created September 11, 2016 03:19
Show Gist options
  • Save ytabuchi/199f9fef435e29a434ee8c872c267281 to your computer and use it in GitHub Desktop.
Save ytabuchi/199f9fef435e29a434ee8c872c267281 to your computer and use it in GitHub Desktop.
Xamarin.Forms の ListView をコードビハインドで書く場合の例
Public partial class CodeBehindPage : ContentPage
{
ObservableCollection<Item> Items = new ObservableCollection<Item>();
public CodeBehindRamenPage()
{
InitializeComponent();
// Items初期化
this.Items.Clear();
// Binding対象にItemsを指定
listView.BindingContext = this.Items;
}
void AddButtonClick(object sender, EventArgs s)
{
this.Items.Add(new Item("MainText", "SubText", "SampleImage.png"));
}
void DeleteButtonClick(object sender, EventArgs s)
{
if (this.Items.Count > 0)
{
this.Items.Remove(this.Items[this.Items.Count - 1]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment