public ScrollableListView(ScrollableListViewModel <D, S, I> scrollableListViewModel) : base(ListViewCachingStrategy.RecycleElement) { this.scrollableListViewModel = scrollableListViewModel; ItemsSource = scrollableListViewModel.Items; HasUnevenRows = true; ItemTemplate = Container.ServiceProvider.GetService(typeof(EntityTemplate <D>)) as EntityTemplate <D>; if (ItemTemplate is null) { Debug.WriteLine("Template Not Found : Using default for object"); ItemTemplate = Container.ServiceProvider.GetService(typeof(EntityTemplate <object>)) as EntityTemplate <object>; } InfiniteScrollBehavior infiniteScrollBehavior = new InfiniteScrollBehavior(); Behaviors.Add(infiniteScrollBehavior); Frame frame = new Frame() { BackgroundColor = Color.Transparent, BorderColor = Color.Transparent, HasShadow = false, Content = new ActivityIndicator() { IsRunning = true } }; frame.SetBinding(IsVisibleProperty, new Binding(InfiniteScrollBehavior.IsLoadingMoreProperty.PropertyName, BindingMode.OneWay, source: infiniteScrollBehavior)); Footer = frame; }
public void DecorateListView(ListView listView, IList <ToolbarItem> toolbarItems = null) { if (_listInited) { return; } _listInited = true; listView.SetBinding(ListView.ItemsSourceProperty, new Binding(nameof(DataSource))); listView.HasUnevenRows = true; listView.IsPullToRefreshEnabled = true; listView.SetBinding(ListView.IsRefreshingProperty, new Binding(nameof(IsRefreshing))); listView.SetBinding(ListView.RefreshCommandProperty, new Binding(nameof(LoadDataCommand))); var behavior = new InfiniteScrollBehavior(); behavior.SetBinding(InfiniteScrollBehavior.IsLoadingMoreProperty, new Binding(nameof(IsScrolling))); listView.Behaviors.Add(behavior); var activityIndicator = new ActivityIndicator() { VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.CenterAndExpand, HeightRequest = 70 }; activityIndicator.BindingContext = this; activityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, new Binding(nameof(IsScrolling))); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, new Binding(nameof(IsScrolling))); listView.Footer = activityIndicator; if (toolbarItems != null) { List <string> items = new List <string>(); foreach (var kvp in sortFields) { items.Add($"{kvp.Key}{ASCENDING}"); items.Add($"{kvp.Key}{DESCENDING}"); } var item = new ToolbarItem() { Icon = "ic_sort_by_alpha_white.png" }; item.Clicked += async(object sender, EventArgs e) => { var selected = await Acr.UserDialogs.UserDialogs.Instance.ActionSheetAsync("Sort", "Cancel", null, null, items.ToArray()); if (!string.IsNullOrEmpty(selected) && selected != "Cancel") { sortSelected(selected); } }; toolbarItems.Add(item); } }
public BsdListView(ListViewCachingStrategy cachingStrategy) : base(cachingStrategy) { this.ItemAppearing += OnItemAppearing; this.ItemTapped += OnItemTapped; this.IsPullToRefreshEnabled = true; this.HasUnevenRows = true; this.SelectionMode = ListViewSelectionMode.None; this.SeparatorVisibility = SeparatorVisibility.None; this.BackgroundColor = Color.FromHex("#eeeeee"); this.SetBinding(RefreshCommandProperty, new Binding("RefreshCommand")); this.SetBinding(IsRefreshingProperty, new Binding("IsRefreshing")); this.SetBinding(ItemsSourceProperty, new Binding("Data")); InfiniteScrollBehavior behavior = new InfiniteScrollBehavior(); behavior.SetBinding(InfiniteScrollBehavior.IsLoadingMoreProperty, new Binding("IsBusy")); this.Behaviors.Add(behavior); }
protected override void OnAppearing() { base.OnAppearing(); if (!viewModel.ForUser && this.ToolbarItems.Count < 2) { if (viewModel.ForSearch) { var srch = new ToolbarItem() { Icon = "ic_search_white.png" }; srch.Clicked += (object sender, EventArgs e) => viewModel.ToggleFilter(); this.ToolbarItems.Add(srch); } else { var toolbarItem = new ToolbarItem() { Icon = "ic_add_white.png" }; toolbarItem.Clicked += addToolbarItem_Click; this.ToolbarItems.Add(toolbarItem); if (viewModel.IsNotGeneral) { toolbarItem = new ToolbarItem() { Icon = "ic_input_white.png" }; toolbarItem.Clicked += Btn_Clicked; this.ToolbarItems.Add(toolbarItem); } } var sort = new ToolbarItem() { Icon = "ic_sort_by_alpha_white.png" }; sort.Clicked += async(object sender, EventArgs e) => await viewModel.ShowSort(); this.ToolbarItems.Add(sort); } if (viewModel.ForSearch) { var behavior = new InfiniteScrollBehavior(); behavior.SetBinding(InfiniteScrollBehavior.IsLoadingMoreProperty, new Binding(nameof(viewModel.IsScrolling))); EntriesList.Behaviors.Add(behavior); var activityIndicator = new ActivityIndicator() { VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.CenterAndExpand, HeightRequest = 70 }; activityIndicator.BindingContext = this; activityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, new Binding(nameof(viewModel.IsScrolling))); activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, new Binding(nameof(viewModel.IsScrolling))); EntriesList.Footer = activityIndicator; } if (viewModel.Entries.Count == 0) { viewModel.LoadEntriesCommand.Execute(null); } }