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

Entry Completed trigger Listview Refresh - MVVM

$
0
0

Hi,

I have a Xam Forms App containing an Entry and a Listview.

I've tried to implement the MVVM design but somethings still puzzle me.

From what I understand, I will do the binding in the View(XAML) for the Listview datasource and data template.
However, I need the search terms to come from the Entry on Complete event, which will trigger a weather service to retrieve an ObservableCollection to be updated into the listview binding.

Currently, I'm doing it like this in the XAML Code Behind:

    ObservableCollection<WeatherResultModel> resultList;
private async void Entry_Completed(object sender, EventArgs e)
    {
        string input = ((Entry)sender).Text;
        if (input != null)
        {
            WeatherService weatherService = new WeatherService();
            resultList = await weatherService.GetForecastByCityOrCountry(input);

            SearchResultListView.ItemsSource = resultList;
        }
    }

How can I do this in a way that fits the MVVM paradigm?

Thanks!


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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