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.

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,681 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,431 questions
XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
768 questions
{count} votes