How to get data from API to wpf mvvm

Emre Geçer 26 Reputation points
2022-06-21T06:37:40.793+00:00

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.

Developer technologies Windows Presentation Foundation
Windows development Windows API - Win32
Developer technologies XAML
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.