1
votes

I have a Xamarin app that I've recently included into a web service using Xamarin, working with a wcf web service, and works fine (http://developer.xamarin.com/guides/cross-platform/xamarin-forms/web-services/consuming/wcf/)

There is a ListView tutorial and this works fine calling the async web service using a Command in the controller, and binding that to the Listview.

So for my problem, What is the best way to load async web service data into the xamarin picker control when the form loads?

I've tried doing something in the viewmodel constructor, but the control data renders before the data comes back....

public class UserPreferencesViewModel : BaseViewModel
  {...

public UserPreferencesViewModel()
    {
       LoadDropdownData();
      //carries on while data is being queried
    }

   async Task LoadDropdownData()
    {

        Services = new ObservableRangeCollection<Service>();
        var services = await App.ServiceManager.GetServiceDataAsync();
        Services.ReplaceRange(services);
    }

And I cannot seem to use a command object as there is no RefreshCommand property.

I also have preference data that i need to set the picker value to, and wondering how best to do this.

Hope this makes sense

1
either use async await correctly .. so in your constructor: await LoadDropdownData or work with ObservableCollections if your data coming async from the WCF Service will populate the ListViewLuca
You cannot use 'await' in the constructor, so ObservableCollections look the way forward? I'm already using ObservableRangeCollections for the Service type.the_tr00per

1 Answers

2
votes

Assigned the xamarin picker to the observable collection and this worked.