public MonkeysPage() { Title = "Monkeys"; var list = new ListView(); var viewModel = new MonkeysViewModel(); list.ItemsSource = viewModel.MonkeysGrouped; list.IsGroupingEnabled = true; list.GroupDisplayBinding = new Binding("Key"); list.GroupShortNameBinding = new Binding("Key"); if(Device.OS != TargetPlatform.WinPhone) list.GroupHeaderTemplate = new DataTemplate(typeof(HeaderCell)); list.HasUnevenRows = true; // if using a custom template for each cell you might want to enable this. var cell = new DataTemplate(typeof(AspectImageCell)); cell.SetBinding(TextCell.TextProperty, "Name"); cell.SetBinding(TextCell.DetailProperty, "Location"); cell.SetBinding(ImageCell.ImageSourceProperty, "Image"); list.ItemTemplate = cell; list.ItemTapped += (sender, args) => { var monkey = args.Item as Monkey; if (monkey == null) return; Navigation.PushAsync(new DetailsPage(monkey)); // Reset the selected item list.SelectedItem = null; }; Content = list; }
public App() { var list = new ListView(); var viewModel = new MonkeysViewModel(); list.ItemsSource = viewModel.Monkeys; var cell = new DataTemplate(typeof(MonkeyCell)); list.RowHeight = Device.OnPlatform(70, 70, 125); list.HasUnevenRows = true; list.ItemTemplate = cell; // The root page of your application MainPage = new ContentPage { Title = "Monkeys", Content = list }; }
public MonkeysPage() { InitializeComponent(); BindingContext = new MonkeysViewModel(); }