Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Updating a listView on itemSource change

$
0
0

Hi I'm pretty new in the Xamarin Forms world and I'm trying to have the listView that I created refresh its content when the itemSource change. Right know I have this:

public NearMe ()
        {
            list=jM.ReadData ();
            listView.ItemsSource = list;
            listView.ItemTemplate = new DataTemplate(typeof(FilialeCell));
            searchBar = new SearchBar {
                Placeholder="Search"
            };
            searchBar.PropertyChanged += (sender, e) => {
                TextChanged(searchBar.Text);
            };
            var stack = new StackLayout { Spacing = 0 };
            stack.Children.Add (searchBar);
            stack.Children.Add (listView);
            Content = stack;
        }
public void TextChanged(String text){
            if (!String.IsNullOrEmpty (text))
                text = text[0].ToString().ToUpper() + text.Substring(1);
            var filterSedi = list.Where (filiale => filiale.nome.Contains(text));
            List<Filiale> newList = filterSedi.ToList ();
            newList = newList.OrderBy (x => x.distanza).ToList();
            listView.ItemSource = newList;
        }

But this is not working, it gives me a blank page at startup, there is no searchBar and neither the listView element. I think that I can't simply assign a new itemSource is this correct? How can I implement this feature? Thank you for your help in advance.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>