Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

how to filter a listview ?

delaiodelaio Member ✭✭


I get a list of appointments with their date and time via an API.

According to the user's choice (see the list of future meetings / see the list of past meetings) I want to filter by date and time but I do not know the best approach. Must:

  • filter listappointment_lv listview ?
  • filter ResponseAPIAppointments object ?
  • create a Appointments class and assign the filtered result to it ?

Regarding the full functionality: I have to display the list of appointments by sorting the date and time in descending order and when I click on an appointment I display a new page with the details of the appointment.

Thank for your advices.

API response

    public class ResponseAPIAppointments
        public class Services
            public string libelle { get; set; }
            public string speaker { get; set; }

        public class Appointments
            public int? id { get; set; }
            public string name { get; set; }
            public int? number { get; set; }
            public DateTime? expirationdate { get; set; }
            public string expirationheure { get; set; }
            public List<Services_cl> services { get; set; }

        public string status_st { get; set; }

        public bool Success_bo { get; set; }

        public string Error_st { get; set; }

        public List<Appointments> AppointmentList { get; set; }


                        <ListView x:Name="listappointment_lv"
                                  ItemsSource="{Binding ResponseAppointments.AppointmentList}"
                                        <Label Padding="10"
                                                    <Span Text="{Binding expirationdate , StringFormat='{0:MM/dd/yyyy}'}}" />
                                                    <Span Text=" " />
                                                    <Span Text="{Binding expirationheure}" />


    public partial class Page : ContentPage
        private ResponseAPIAppointments _responseAppointments ;
        public ResponseAPIAppointments ResponseAppointments 
            set  {  _responseAppointments = value; OnPropertyChanged();  }
            get => _responseAppointments ;

        public Page(string pastfuture)
       // call API
       // ResponseAppointments object fill

            BindingContext = this;


  • JohnHardmanJohnHardman GBUniversity admin
    edited October 16


    Create a new ObservableCollection property in your ViewModel. Have that initially populated with the data from ResponseAppointments.AppointmentList . When the user changes the filter or sort criteria, have your ViewModel update that new collection by filtering/sorting data from AppointmentList. Change the binding of ListView.ItemsSource to bind to that new property.

  • delaiodelaio Member ✭✭

    thank you John for this answer.

  • JohnHardmanJohnHardman GBUniversity admin

    @delaio said:
    thank you John for this answer.

    If you find answers helpful, don't forget to Like them (and if they were asked as Questions rather than Discussions, don't forget to mark them as Accepted Answer) :-)

Sign In or Register to comment.