private async Task InitializeCollectionView() { UINib nib = UINib.FromName(SaleItemViewCell.Key, null); SaleItemsCollectionView.RegisterNibForCell(nib, SaleItemViewCell.Key); nib = UINib.FromName(SellArticleButtonViewCell.Key, null); SaleItemsCollectionView.RegisterNibForCell(nib, SellArticleButtonViewCell.Key); saleItemsSource = new SaleItemsDataSource(); saleItemsSource.SellRequestedCallback = OnSellRequested; saleItemsSource.SaleItemSelectedCallback = OnSaleItemSelected; SaleItemsCollectionView.Source = saleItemsSource; await SaleItemDataService.Instance.Initialize(); // As each item image download may occur after its cell is loaded, // we should reload it when that download is completed SaleItemDataService.Instance.MobileService.EventManager .Subscribe <FileDownloadedEvent>(file => { SaleItemsCollectionView.BeginInvokeOnMainThread(() => { var targetCell = SaleItemsCollectionView.VisibleCells .OfType <SaleItemViewCell>() .FirstOrDefault(c => c.ItemId == file.Name); if (targetCell != null) { NSIndexPath path = SaleItemsCollectionView.IndexPathForCell(targetCell); SaleItemsCollectionView.ReloadItems(new[] { path }); } }); }); }
private async Task LoadSaleItems() { UserDialogs.Instance.ShowLoading("Loading..."); IEnumerable <SaleItem> data = await SaleItemDataService.Instance.GetSaleItems(); saleItemsSource.Items = data; SaleItemsCollectionView.ReloadData(); UserDialogs.Instance.HideLoading(); }