How to get data from API to wpf mvvm
Emre Geçer
26
Reputation points
I have Wpf application. I need to get data from api to wpf. I have treeview and i wanna put the data to treeview`ublic async void GetAllEmployee()
{
using (HttpClient client = new HttpClient())
{
try
{
HttpResponseMessage response = await client.GetAsync($"{conURL}/GetEmployee");
response.EnsureSuccessStatusCode();
if (response.IsSuccessStatusCode)
{
MessageBox.Show("Value getted");
}
else
{
MessageBox.Show("failed");
}
//deserialization
IList<EmployeeModel> ls =
await response.Content.ReadAsAsync<IList<EmployeeModel>>();
GetAll(ls);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "May server not running");
}
}
This is how i tried to get data but i cannot use in viewmodel.