protected override async void OnAppearing() { try { ListOfFamily = new List <FamilyList>(); RestClient restClient = App.restClient; var families = await restClient.Get <List <FamilyWrap> >("families/location"); if (families != null) { //families = families.OrderBy(x => x.Name).ToList(); var lstUserEmpty = families.Where(x => x.location == null); var lstAlphabet = families.Where(x => x.location != null).Select(y => y.location).ToList(); lstAlphabet = lstAlphabet.GroupBy(x => x.LocationId).Select(y => y.FirstOrDefault()).ToList(); FamilyList familyList = null; foreach (var item in lstAlphabet) { familyList = new FamilyList(); var heading = item; var lstTemp = families.Where(x => x.location != null && x.location.LocationId == item.LocationId).ToList(); familyList.Heading = heading.Name; foreach (var ele in lstTemp) { ele.family.Location = ele.location; } familyList.AddRange(lstTemp.Select(x => x.family).ToList()); ListOfFamily.Add(familyList); } if (lstUserEmpty.Any()) { familyList = new FamilyList(); ListOfFamily.Add(familyList); familyList.Heading = "Unknow"; foreach (var ele in lstUserEmpty) { ele.family.Location = ele.location; } familyList.AddRange(lstUserEmpty.Select(x => x.family).ToList()); } ItemsListView.ItemsSource = ListOfFamily; } ItemsListView.ItemsSource = ListOfFamily; } catch (Exception ex) { } base.OnAppearing(); }