<dataForm:DataFormDropDownItem Name="Client"
Editor="DropDown"
BindingContext="{StaticResource client}"
ItemsSource="{Binding Clients}"
DisplayMemberPath="Nom"
SelectedValuePath="Nom"/> |
public class ClientViewModel : INotifyPropertyChanged
{
private ObservableCollection<Client> clients;
public ObservableCollection<Client> Clients
{
get { return clients; }
set
{
clients = value;
this.RaiseOnPropertyChanged("Clients");
}
}
public ClientViewModel()
{
Clients = new ObservableCollection<Client>();
this.GetValue();
}
public async Task GetClient()
{
Clients.Clear();
HttpClient Connexion = new HttpClient();
var resp = await Connexion.GetAsync(“url to fetch data”);
if (resp.IsSuccessStatusCode)
{
var content = await resp.Content.ReadAsStringAsync();
var client = JsonConvert.DeserializeObject<ObservableCollection<Client>>(content);
var clientsDatata = new ObservableCollection<Client>();
foreach (var j in client)
clientsDatata.Add(j);
this.Clients = clientsDatata;
}
}
private async void GetValue()
{
await this.GetClient(); ;
}
public event PropertyChangedEventHandler PropertyChanged;
private void RaiseOnPropertyChanged(string propertyName)
{
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
} |