locked
How to apply pagination in lisview using Xamarin forms cross platform? RRS feed

  • Question

  • User393719 posted

    How to apply pagination in lisview using Xamarin forms cross platform? Please help.I have searched on google but couldn't find the solution. Thanks in advance

    Wednesday, July 29, 2020 7:34 AM

All replies

  • User382871 posted

    How to apply pagination in lisview using Xamarin forms cross platform? @DemoCloud ListView doesn't has the indicator part like CarouselView. What effect do you want to achieve?

    If you want the effect like above, try to add a Label in the ViewCell to display the 'pagination'.

    Wednesday, July 29, 2020 9:42 AM
  • User393719 posted

    @YelinZh , I want to display the pagination like previous next. Initially the page should display 20 items from the list when clicked on next 2nd page list items should be displayed(21 to 40) and so on. please help me Thanks

    Thursday, July 30, 2020 5:12 AM
  • User382871 posted

    I want to display the pagination like previous next. Initially the page should display 20 items from the list when clicked on next 2nd page list items should be displayed(21 to 40)

    ListView doesn't provide the function directly. To achieve this feature, you could add two buttons on the page and change the itemsSource of the listView to update the data in the click event.

    Check the code:

    Page.xaml ```

    <ListView x:Name="listview" ItemsSource="{Binding Models}" Grid.Row="0">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    ...
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
    
    <StackLayout Orientation="Horizontal" VerticalOptions="EndAndExpand" Grid.Row="1" BackgroundColor="Transparent">
        <Button x:Name="previous" Text="Previous" Clicked="PreviousButton_Clicked" IsEnabled="false"/>
        <Button x:Name="next" Text="Next" Clicked="NextButton_Clicked" HorizontalOptions="EndAndExpand"/>
    </StackLayout>
    

    Page.xaml.cs public partial class Page4 : ContentPage { public Dictionary> dictionary { get; set; } int number = 1;

    public Page4()
    {
        InitializeComponent();
    
        ViewModel_4 viewModel = new ViewModel_4();
        dictionary = viewModel.dataDictionary;
    
        listview.ItemsSource = dictionary[number];
    }
    
    private void PreviousButton_Clicked(object sender, EventArgs e)
    {
        next.IsEnabled = true;
        listview.ItemsSource = dictionary[--number];
        if (number == 1)
        {
            previous.IsEnabled = false;
        }
    }
    private void NextButton_Clicked(object sender, EventArgs e)
    {
        previous.IsEnabled = true;
        listview.ItemsSource = dictionary[++number];
        if (number == dictionary.Count)
        {
            next.IsEnabled = false;
        }
    }
    

    } ```

    Model class and ViewModel class ``` public class Model_4 { public string content { get; set; } }

    public class ViewModel4 { public ViewModel4() { dataDictionary = new Dictionary>(); //add data to the dictionary }

    public Dictionary<int, ObservableCollection<Model_4>> dataDictionary { get; set; }
    

    } ```

    !

    Thursday, July 30, 2020 9:17 AM