When the list is popular, it is null

1

In my App I populate two grids. This is okay. I get data from a service, like this:

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

This is correct. Well, I happen to need to generate a chart with some information from the item grid. On the chart page I tried to do something similar, but it is not working and apparently should not. In the graphic page I tried to do similar to what I was doing on the other page and it is not working, I did this:

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

How can I get the data that comes from the service. I need to do a calculation before and then generate the graph. Awaiting. Method that takes the 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 too. I did so:

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

and tried it popular like this:

Itens = await dataService.GetItensLibAsync(idorcamento);

    
asked by anonymous 15.10.2017 / 19:00

0 answers