Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- namespace ListViewDemoVS
- {
- class MyContentPage : ContentPage
- {
- ObservableCollection<Item> items = new ObservableCollection<Item>
- {
- new Item { Title = "First", Description = "1st" },
- new Item { Title = "Second", Description = "2nd" },
- new Item { Title = "Third", Description = "3rd" }
- };
- public MyContentPage()
- {
- Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
- var listView = new ListView();
- listView.ItemsSource = items;
- listView.ItemTemplate = new DataTemplate(typeof(TextCell));
- listView.ItemTemplate.SetBinding(TextCell.TextProperty, "Title");
- listView.ItemTemplate.SetBinding(TextCell.DetailProperty, "Description");
- listView.ItemTapped += async (sender, e) =>
- {
- Item item = (Item)e.Item;
- await DisplayAlert("Tapped", item.Title.ToString() + " was selected.", "OK");
- ((ListView)sender).SelectedItem = null;
- };
- Button buttonRemove = new Button
- {
- Text = "Delete Row",
- FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Button)),
- HorizontalOptions = LayoutOptions.Center,
- VerticalOptions = LayoutOptions.Fill
- };
- buttonRemove.Clicked += (sender, e) =>
- {
- items.RemoveAt(0);
- };
- Content = new StackLayout
- {
- Children = { buttonRemove, listView }
- };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement