private void RenderSections(IEnumerable <Section> sections, Action moreAction) { var root = new RootElement(Title) { UnevenRows = Root.UnevenRows }; foreach (var section in sections) { root.Add(section); } var elements = root.Sum(s => s.Elements.Count); //There are no items! We must have filtered them out if (elements == 0) { root.Add(new Section { new NoItemsElement(NoItemsText) }); } if (moreAction != null) { var loadMore = new PaginateElement("Load More", "Loading...") { AutoLoadOnVisible = true }; root.Add(new Section { loadMore }); loadMore.Tapped += async(obj) => { try { await this.DoWorkNoHudAsync(() => Task.Run(moreAction)); if (loadMore.GetImmediateRootElement() != null) { var section = loadMore.Parent as Section; Root.Remove(section, UITableViewRowAnimation.Fade); } } catch (Exception e) { Utilities.ShowAlert("Unable to load more!", e.Message); } }; } Root = root; }
private static ICollection <Section> RenderSections(IEnumerable <Section> sections, Action moreAction) { var weakAction = new WeakReference <Action>(moreAction); ICollection <Section> newSections = new LinkedList <Section>(sections); if (moreAction != null) { var loadMore = new PaginateElement("Load More", "Loading...") { AutoLoadOnVisible = true }; newSections.Add(new Section { loadMore }); loadMore.Tapped += async(obj) => { try { NetworkActivity.PushNetworkActive(); var a = weakAction.Get(); if (a != null) { await Task.Run(a); } var root = loadMore.GetRootElement(); root?.Remove(loadMore.Section, UITableViewRowAnimation.Fade); } catch (Exception e) { AlertDialogService.ShowAlert("Unable to load more!", e.Message); } finally { NetworkActivity.PopNetworkActive(); } }; } return(newSections); }