protected override void Init() { var label = new Label { Text = Instructions, }; grouped = new ObservableCollection <GroupedItem>(); lstView = new ListView() { IsGroupingEnabled = true, HasUnevenRows = true, ItemTemplate = new DataTemplate(typeof(MyViewCell)), GroupHeaderTemplate = new DataTemplate(typeof(MyHeaderViewCell)), ItemsSource = grouped, AutomationId = "TestReady" }; var grp1 = new GroupedItem() { LongName = "Group 1", ShortName = "1" }; var grp2 = new GroupedItem() { LongName = "Group 2", ShortName = "2" }; for (int i = 1; i < 4; i++) { grp1.Add($"I am a short text #{i}"); grp1.Add($"I am a long text that should cause the line to wrap, and I should not be cut off or overlapping in any way. #{i}"); grp2.Add($"I am a short text #{i}"); grp2.Add($"I am a long text that should cause the line to wrap, and I should not be cut off or overlapping in any way. #{i}"); } grouped.Add(grp1); grouped.Add(grp2); Content = new StackLayout { Children = { label, lstView } }; }
private async void FilterGroupItems(string searchString) { try { searchString = searchString.ToLower(); if (!string.IsNullOrEmpty(searchString)) { var groupedList = new ObservableCollection <GroupedItem <Patient> >(); var xlist = (await _patientsStorage.GetList()); var patientsList = xlist.Where(x => x.Fullname.ToLower().Contains(searchString)).ToList(); var headers = patientsList.Select(x => x.LastName.Substring(0, 1)).Distinct().OrderBy(x => x); foreach (var headerkey in headers) { var patientGroup = new GroupedItem <Patient> { HeaderKey = headerkey }; var list = new List <Patient>(); foreach (var item in patientsList.Where(x => x.LastName.StartsWith(headerkey, StringComparison.OrdinalIgnoreCase)).ToList()) { list.Add(item); } list = list.OrderBy((arg) => arg.Fullname).ToList(); foreach (var item in list) { patientGroup.Add(item); } groupedList.Add(patientGroup); } _filteredPatients = (ObservableCollection <GroupedItem <Patient> >)(object) groupedList; ItemsSource = _filteredPatients; } else { ItemsSource = Patients; //await GetDataAsync(); } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
private void GroupItems(List <Patient> observableCollection) { try { var groupedList = new ObservableCollection <GroupedItem <Patient> >(); var patientsList = observableCollection.Cast <Patient>().ToList(); var headers = patientsList.Select(x => x.LastName.Substring(0, 1)); headers = headers.Select(h => char.ToUpper(h[0]).ToString()).Distinct().OrderBy(x => x); foreach (var headerkey in headers) { var patientGroup = new GroupedItem <Patient> { HeaderKey = headerkey }; var list = new List <Patient>(); foreach (var item in patientsList.Where(x => x.LastName.StartsWith(headerkey, StringComparison.OrdinalIgnoreCase)).ToList()) { list.Add(item); } list = list.OrderBy((arg) => arg.Fullname).ToList(); foreach (var item in list) { patientGroup.Add(item); } groupedList.Add(patientGroup); } Patients = groupedList; ItemsSource = groupedList; } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
protected override void Init() { var label = new Label { Text = Instructions, AutomationId = "TestReady" }; grouped = new ObservableCollection <GroupedItem>(); lstView = new ListView(ListViewCachingStrategy.RecycleElement) { IsGroupingEnabled = true, ItemTemplate = new DataTemplate(typeof(AccessoryViewCell)), ItemsSource = grouped, GroupDisplayBinding = new Binding("LongName"), GroupShortNameBinding = new Binding("ShortName") }; var grp1 = new GroupedItem() { LongName = "Group 1", ShortName = "1" }; var grp2 = new GroupedItem() { LongName = "Group 2", ShortName = "2" }; for (int i = 1; i < 4; i++) { grp1.Add($"Item #{i}"); grp2.Add($"Item #{i}"); } grouped.Add(grp1); grouped.Add(grp2); Content = new StackLayout { Children = { label, lstView } }; }