How to access a list of another class in C #

3

I'm trying to access the ContactList of the Contact class in the ContactList class to view. The problem is that although the list is populated in Contact, it is empty in the Contact List.

    public class Contato
        {
            string Nome { get; set; }
            string Numero {get; set; }

            public List<Contato> ListaDeContatos = new List<Contato>();
            public async void Buscar()
            {
                 ContactStore contactStore;
                 contactStore = await ContactManager.RequestStoreAsync();
                 var contatos = await contactStore.FindContactsAsync();

                 foreach (var item in contatos)
                 {
                      if (!string.IsNullOrEmpty(item.FirstName))
                      {                                      
                           ListaDeContatos.Add(new Contato() { Nome = item.FirstName.ToString() + " " + item.LastName.ToString(), Numero = "12345678" });
                 }
            }
    }

        public sealed partial class ListaContatos : Page
    {       
        public ListaContatos()
        {
...         
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            Contato contato = new Contato();
            contato.Buscar();
            listView.ItemsSource = contato.ListaDeContatos;
        }
    
asked by anonymous 31.10.2015 / 14:20

1 answer

1

Your Search () method has no return and you are using a static variable within the Find () method, so you will not be able to populate your ContactList object.

Create the fetch method and return the filled list:

 public async ListaDeContatos Buscar()
 {
   return ListaDeContatos;
 }
    
20.01.2017 / 18:02