Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Xamarin.Forms;
- namespace ListViewDemoVS
- {
- class MyContentPage : ContentPage
- {
- public MyContentPage()
- {
- Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
- ListView listView = new ListView();
- listView.ItemsSource = new ListItem[] {
- new ListItem { Title = "First", Description = "1st", Source="one.jpg" },
- new ListItem { Title = "Second", Description = "2nd", Source="two.jpg" },
- new ListItem { Title = "Third", Description = "3rd", Source="three.jpg" }
- };
- listView.ItemTemplate = new DataTemplate(typeof(ImageCell));
- listView.ItemTemplate.SetBinding(ImageCell.TextProperty, "Title");
- listView.ItemTemplate.SetBinding(ImageCell.DetailProperty, "Description");
- listView.ItemTemplate.SetBinding(ImageCell.ImageSourceProperty, "Source");
- /*
- listView.ItemTapped += async (sender, e) =>
- {
- await DisplayAlert("Tapped", e.Item.ToString(), "OK");
- ((ListView)sender).SelectedItem = null;
- };
- */
- listView.ItemSelected += async (sender, e) =>
- {
- if (e.SelectedItem == null) return;
- ListItem item = (ListItem)e.SelectedItem;
- await DisplayAlert("Selected", ((ListItem)(e.SelectedItem)).Title, "OK");
- ((ListView)sender).SelectedItem = null;
- };
- this.Content = listView;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement