To the popular the list, is coming null

Asked

Viewed 47 times

1

In my App I populate two grids. That’s ok. I take the data of a service, that way:

dataGrid.ItemsSource = await dataService.GetLiberaAsync();
itensGrid.ItemsSource = await dataService.GetItensLibAsync(_idorcamento);

That’s correct. Well, it turns out I need to generate a graph with some information from the item grid. On the chart page I tried to do something similar, but it’s not working and apparently it shouldn’t. On the chart page I tried to do similar to what I was doing on the other page and it’s not working, I did so:

List<ItensLib> item = new List<ItensLib>();
.......
private async void RetornaItens(double idorcamento)
{
    item = await dataService.GetItensLibAsync(idorcamento);
}

How can I get the data coming from the service. I need to do a calculation before and then generate the graph. No waiting. Method that picks up data in the service.

public async Task<List<ItensLib>> GetItensLibAsync(double id)
        {
            try
            {
                string url = $"http://www.meu_site.com.br/autorizador/api/itens/{id}";
                var response = await client.GetStringAsync(url);
                var itenslib = JsonConvert.DeserializeObject<List<ItensLib>>(response);
                return itenslib.ToList();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

I also created a Property and nothing either. I did so:

private List<ItensLib> itens;
        public List<ItensLib> Itens
        {
            get
            {
                return itens;
            }
            set
            {
                if (value != null)
                    itens = value;
            }
        }

and tried to popular so:

Itens = await dataService.GetItensLibAsync(idorcamento);

  • How are the data coming? Have you tried a cast? await dataService.GetItensLibAsync(idorcamento).Cast<ItensLib>();

  • @Francisco, no, I didn’t even think about it. I’ll try. What I did too, was to create a Property and still nothing, but I’ll go on your line.

  • @Francisco, error, saying it doesn’t have a definition for Cast. See my edit

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.