We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to filter Xamarin.Forms ListView (SfListView) using MVVM

You can filter ListViewItems in MVVM using behavior in Xamarin.Forms SfListView.


Define the ContentPage behavior.

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
        <Grid x:Name="MainGrid" Margin="{OnPlatform iOS='0,40,0,0'}">
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            <SearchBar x:Name="filterText" Placeholder="Search here to filter" />
            <sync:SfListView x:Name="listView" ItemsSource="{Binding Items}" Grid.Row="1" ItemSpacing="0,5,0,5" BackgroundColor="#F0F0F0" ItemSize="100">
                    <DataTemplate x:Name="ItemTemplate" >
                        <Frame OutlineColor="#b3b3b3" Padding="2" Margin="10,0,10,0">
                            <Grid BackgroundColor="White" Padding="10">
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                    <RowDefinition Height="Auto"/>
                                <Label x:Name="TitleLabel" LineBreakMode="NoWrap" Text="{Binding Title}" FontAttributes="Bold" TextColor="Black"/>
                                <Label Grid.Row="1" x:Name="DescriptionLabel" Text="{Binding Description}" TextColor="Teal"/>
                                <Frame Grid.Row="2" Padding="4,2,4,2" BackgroundColor="#FFE7E8E9" HorizontalOptions="Start" VerticalOptions="End">
                                    <Label x:Name="TagLabel" LineBreakMode="NoWrap" Text="{Binding Tag}" FontSize="10" TextColor="Black"/>


Trigger the TextChanged event of the SearchBar control to filter the ListView based on the SearchText. Set the Filter predicate for ListView to filter the items and call the RefreshView method.

namespace ListViewXamarin
    public class Behavior : Behavior<ContentPage>
        SfListView ListView;
        SearchBar SearchBar;
        protected override void OnAttachedTo(ContentPage bindable)
            ListView = bindable.FindByName<SfListView>("listView");
            SearchBar = bindable.FindByName<SearchBar>("filterText");
            SearchBar.TextChanged += SearchBar_TextChanged;
        private void SearchBar_TextChanged(object sender, TextChangedEventArgs e)
            if (ListView.DataSource != null)
                ListView.DataSource.Filter = FilterContacts;
        private bool FilterContacts(object obj)
            if (SearchBar == null || SearchBar.Text == null)
                return true;
            var taskInfo = obj as TaskInfo;
            return (taskInfo.Title.ToLower().Contains(SearchBar.Text.ToLower())
                || taskInfo.Description.ToLower().Contains(SearchBar.Text.ToLower()));


Filter Xamarin.Forms SfListView using MVVM.

View sample in GitHub

2X faster development

The ultimate Xamarin UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile