I am trying to put the results I get from an API to a picker. And that is the way I am doing it.
public partial class AddTaskPage : ContentPage
{
public AddTaskPage()
{
InitializeComponent();
BindingContext = this;
}
private async void GetUsers()
{
using (var client = new HttpClient())
{
var uri = "http://diplomaxmcws-dev.us-east-2.elasticbeanstalk.com/api/Users/GetAllUsers";
var result = await client.GetStringAsync(uri);
var ResultList = JsonConvert.DeserializeObject<List<XMCUsers>>(result);
Users = new ObservableCollection<XMCUsers>(ResultList);
BindingContext = this; // for sureness
}
}
public ObservableCollection<XMCUsers> Users { get; set; }
protected override void OnAppearing()
{
GetUsers();
BindingContext = this; //for sureness
}
}
and in the XAML file.
<Picker Margin="20,40,20,0"
HeightRequest="50" Title="Choose"
ItemsSource="{Binding Users}"
ItemDisplayBinding="{Binding Full_Name}"
x:Name="ddProfession">
From debugging I see that the Users property gets the results correctly from the API, but binding won't show anything in the view. I don't know if it has to do something with GetUsers() method since it is async. Any help is much valued.