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

Binding to an asynchronous REST service

I am using a Xamarin Forms SfDataGrid and I want to call a REST service asynchronously and bind the data returned to the SfDataGrid.

       <syncfusion:SfDataGrid x:Name="dgPortfolios" Grid.Column="0" Grid.Row="1" ItemsSource="{Binding Portfolios}"
                               VerticalOptions="FillAndExpand" ColumnSizer="Star" AllowSorting="True">
                <local:PortfolioViewModel />


 public class PortfolioViewModel
        ITradingService _tradingService;

        public ObservableCollection<PortfolioPerformance> Portfolios { get; set; }
        public PortfolioViewModel()

        public async void Load()
            var http = new HttpClient(new NativeMessageHandler());
            http.BaseAddress = new Uri(AppConstants.TradingServiceURL);
            _tradingService = Refit.RestService.For<ITradingService>(http);

           var portfolios = await _tradingService.SearchPortfolio();
           Portfolios = new ObservableCollection<PortfolioPerformance>(portfolios);


The Load event is triggered but possibly doesn't finish in time to set Portfolios as Portfolios is null when it is triggered.

6 Replies

DD Dharmendar Dhanasekar Syncfusion Team May 9, 2016 01:00 PM UTC

[‎5/‎9/‎2016 6:30 PM] Vimal Prabhu Manohkaran:  
Hi Paul,

Thanks for contacting Syncfusion Support. We are working on your requirement and trying to replicate the reported issue. We will get back to you with the working sample on 11-5-16.


AP Ashwini Paranthaman Syncfusion Team May 12, 2016 04:05 AM UTC

From: Paul Howells
Sent: Wednesday, May 11, 2016 8:57 PM
To: Syncfusion Support
Subject: RE: Syncfusion support community forum 124002, Binding to an asynchronous REST service, has been updated.
How did you go with this issue? Is there any progress? 

AR Akila Rajaram Syncfusion Team May 13, 2016 06:04 AM UTC

Hi Paul, 
We are able to reproduce the reported problem while fetching the data asynchronously . We are current checking on this . We have attached the sample we tried for your reference and we will update further details on 13th May 13, 2016.  
Akila R. 

AR Akila Rajaram Syncfusion Team May 17, 2016 01:32 PM UTC

Hi Paul,  

We are sorry for the delay. 

We were able to load the data from service using ODataClient . Initially, we were able to reproduce the issue which occurred because of slow internet connection. However, when testing our sample with a good internet connection we were able to load the data from the services. We have attached the sample and a video for your reference which you can download from the below link.  

Akila R. 

PA Paul May 18, 2016 08:25 AM UTC

I have run the sample project using the UWP project and then the Windows Phone as the start up project. Both projects run successfully but the datagrid is not displayed at all.
I tried simplifying the LoadData method to remove the dependency on the OData service but still the datagrid is not displayed:

async void LoadData()
            //gridSource = new ObservableCollection<Order>();
            //var client = new ODataClient("http://services.odata.org/Northwind/Northwind.svc/");
            //var units = await client.FindEntriesAsync("Orders");
            //var itemCollection = units.ToList();

            //var itemCollection1 = new List<IDictionary<string, object>();
            //itemCollection.Add("test", new Order { OrderID = 1, OrderDate = DateTime.Today });

            Device.BeginInvokeOnMainThread(() =>
                //foreach (var item in itemCollection)
                //    var order = new Order();
                //    foreach (var prop in item)
                //    {
                //        order.GetType().GetRuntimeProperty(prop.Key).SetValue(order, prop.Value);
                //    }
                //    gridSource.Add(order);
                Order order = new Order();
                order.OrderID = 1;
                order.OrderDate = DateTime.Today;

Your comment "Initially, we were able to reproduce the issue which occurred because of slow internet connection" is also a concern as I would expect the data to still be displayed even if the OData service takes a while.


AR Akila Rajaram Syncfusion Team May 19, 2016 10:59 AM UTC

Hi Paul,  
We have created an incident for the reported problem. We will assist you further through the incident under your Direct-Trac account. Our Direct Trac support system can be accessed from the following link:   
Akila R. 

Live Chat Icon For mobile
Up arrow icon