private async void OnSelectCategoryCommandExecuted(Grouping <Models.Category, Item> categoryGroup) { if (categoryGroup == null) { return; } if (categoryGroup.Key.Name.Equals("Home")) { await NavigationService.NavigateAsync("NavigationPage/HomePage"); return; } categoryGroup.Key.IsSelected = !categoryGroup.Key.IsSelected; if (categoryGroup.Key.IsSelected) { var category = MenuService.Categories.FirstOrDefault(x => x.Key.Name == categoryGroup.Key.Name); IEnumerable <Item> itemslist = category; categoryGroup.AddRange(itemslist); } else { categoryGroup.Clear(); } }
public static IEnumerable <IGrouping <int, T> > GroupAt <T>(this IEnumerable <T> source, int itemsPerGroup) { for (int i = 0; i < (int)Math.Ceiling((double)source.Count() / itemsPerGroup); i++) { var currentGroup = new Grouping <int, T> { Key = i }; currentGroup.AddRange(source.Skip(itemsPerGroup * i).Take(itemsPerGroup)); yield return(currentGroup); } }