Forum Xamarin.Forms

how can i do this in my app.

Hi,
I want to load my product category and products in same pages with scroll loading. how can i do this in my xamarin forms projects. Help needed.

Thanks in advance.

Answers

  • Adeel984Adeel984 Member ✭✭✭

    Use ItemAppearing Event for ListView when reach at the the last point Use ActivityIndicator make it visible when data loads make it invisible.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited February 2020

    To implement Load more function , you could use ItemAppearing event to trigger the LoadMoreCommand ,handle the items(bind with listview's itemsource) in the commond method .

    Core code

        public class InfiniteListView : ListView
        {
            public static readonly BindableProperty LoadMoreCommandProperty = BindableProperty.Create<InfiniteListView, ICommand>(bp => bp.LoadMoreCommand, default(ICommand));
    
            public ICommand LoadMoreCommand
            {
                get { return (ICommand) GetValue(LoadMoreCommandProperty); }
                set { SetValue(LoadMoreCommandProperty, value); }
            }
    
            public InfiniteListView()
            {
                ItemAppearing += InfiniteListView_ItemAppearing;
            }
    
            void InfiniteListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
            {
                var items = ItemsSource as IList;
    
                if (items != null && e.Item == items[items.Count - 1])
                {
                    if(LoadMoreCommand != null && LoadMoreCommand.CanExecute(null))
                        LoadMoreCommand.Execute(null);
                } 
            }
        }
    

    Refer https://stackoverflow.com/a/43107158/8187800

  • baruasgrpsbaruasgrps Member ✭✭

    Thanks for replay.
    I have done the loadmore using Infinite-Scroll nuget package.
    Basically i question is i have sub-category top of the pages after that i want to show related product of the category. when user scroll the page product load. Like this below.

    Thank in advance.

  • ColeXColeX Member, Xamarin Team Xamurai

    The first part

    The second part

    Let's say you have create buttons in Grid or CollectionView for first part , you can retrieve the list by the id binding on the button when clicking on it ,and change the listView.ItemsSource .

       private void Button_Clicked(object sender, EventArgs e)
        {
            var model = ((Button)sender).BindingContext as Model;
            listView.ItemsSource = list.Select(v => v.ID == model.ID).ToList();
        }
    
Sign In or Register to comment.