How i can convert a Task<List<Model>> result from webservice to an ObservableCollection?

Hello to everyone,

I get a data from webservice, but when I pass the Task<List> to the listview binding, i get an error of converting: "You can not implicitly convert the type system.threading.task.task<system.collections.generic.list> to system.collections.generic.ienumerable"

I was searching but i cant find the code to convert this.

Can anyone help me?

Thanks!

BTW:

this is my method that connect to the webservice, work fine:

public async Task<List<Casos>> ConsultarCasosWebService(int id_cliente, string token)
        {

            clienteHttp = new HttpClient();
            var direURL = "http://192.168.58.29:83/api/caso/cliente/"+ id_cliente +"/?api_token="+ token;
            var uri = new Uri(string.Format(direURL, string.Empty));

            var response = await clienteHttp.GetAsync(uri);
            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();
                cases = JsonConvert.DeserializeObject<List<Casos>>(content);

            }
            return cases;
        }

and this is part of where i need to bind the itemsource of my listview, dont work.

casosService = new CargarCasosService();
            //casos = new ObservableCollection<Casos>(casosService.ConsultarCasos());
            casosWeb = new ObservableCollection<Casos>(casosService.ConsultarCasosWebService(1, "token=="));

            //transgormando el task a ienumerable
            IEnumerable<Casos> casosw = casosWeb;

            //cargando la lista de la vista y creando el evento de seleccion
            lstCases.ItemsSource = casosweb;
            lstCases.ItemSelected += LstCases_ItemSelected;

Best Answer

Answers

  • juanzeta33juanzeta33 USMember ✭✭

    hey @JohnMiller , thank you so much, this work fine to me.

Sign In or Register to comment.