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

How to bind data to ListView control in Xamarin.Form using Async

$
0
0

Hi, I am new to the Xamarin mobile application development.

I am creating one application using Xamarin.forms. I am using PCL to share the code across 3 devices. In the PCL I have created ContentPage class to populate the data into ListView control. I am using asynchronous method calls to populate the data. But I am unable to bind the data into the ListView. Please see my code blow.

Please provide the solution for this.

**ContentPage Class Code : **

 public class ParkInfoPage : ContentPage
{
    public ParkInfoPage()
    {}

    public void GetParkDataInfo()
    {
        Title = "Parking Info";
        var list = new ListView();
        PCL_Proj.ParkInfoAPIData objCls = new PCL_Proj.ParkInfoAPIData();
        GetData(list);
        var cell = new DataTemplate(typeof(TextCell));
        cell.SetBinding(TextCell.TextProperty, "D_name");
        cell.SetBinding(TextCell.DetailProperty, "Address");
        list.ItemTemplate = cell;
    }
    private async Task GetData(ListView objListView)
    {
        //await Task.Delay(TimeSpan.FromSeconds(5)).ConfigureAwait(false);
        var objResultCls = new PCL_Proj.ParkInfoAPIData();
        var result = await objResultCls.GetDataAsync();           
        objListView.ItemsSource = result;            
    }

}

**App Class code : **

 public class App
 {
    public static Page GetMainPage()
    {
        var objParkInfoPage = new ParkInfoPage();
        objParkInfoPage.GetParkDataInfo();
        return new NavigationPage(objParkInfoPage); 
    }
 }

Thanks, Hima


Viewing all articles
Browse latest Browse all 58056

Trending Articles



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