Exemplo n.º 1
0
        public ExpandableGroupsListViewModel()
        {
            MessagingCenter.Subscribe <GroupViewModel>(this, "UpdateSelectedItemsCountMessage", (e) => { UpdateSelectedItemsCount(); });

            Task.Run(async() =>
            {
                IsBusy = true;
                var livingItemsDataServicce = new LifeDataService();
                var livingItems             = (await livingItemsDataServicce.GetItemsAsync()).ToList();
                var groups = livingItems.GroupBy(x => x.Category).Select(x => new ObservableGroupCollection <string, LifeOnPlanetModel>(x)).ToList();
                IsBusy     = false;

                //This is required to invoke on main thread otherwise it will throw the exception
                Device.BeginInvokeOnMainThread(() =>
                {
                    foreach (var group in groups)
                    {
                        GroupedItems.Add(
                            new GroupViewModel
                            (
                                groupTitle: group.Key,
                                groupChildItems: group.Select(i => new GroupItemModel(i.Id, i.Name, i.IsSelected)).ToList()
                            ));
                    }

                    //Show selected items count initialy when page loads
                    UpdateSelectedItemsCount();
                });
            });
        }
Exemplo n.º 2
0
        public BasicGroupingViewModel()
        {
            Task.Run(async() =>
            {
                IsBusy = true;
                var livingItemsDataServicce = new LifeDataService();
                var livingItems             = (await livingItemsDataServicce.GetItemsAsync()).ToList();

                GroupedItems = livingItems.GroupBy(x => x.Category).Select(x => new ObservableGroupCollection <string, LifeOnPlanetModel>(x)).ToList();
                IsBusy       = false;
            });
        }