ListView Databind Xamarin Forms

0

I'm creating an application with Xamarin forms. The application has a student profile screen where I need to display the Model phone list. It turns out that when I do listview binding, all other form bindings stop working. Does anyone have any idea what it can be?

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="GeoMobile.Views.DadosCadastrais">
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto"></ColumnDefinition>
      <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
      <RowDefinition Height="Auto"></RowDefinition>
    </Grid.RowDefinitions>
    <Label Text="Foto" Grid.Row="0" Grid.Column="0" />
    <StackLayout  Grid.Row="0" Grid.Column="1">
      <Label Text="{Binding Aluno.Nome}" />
      <Label Text="{Binding Aluno.DataNascimento, StringFormat='{0:dd/MM/yyyy}'}" />
      <Label Text="{Binding Aluno.RG, StringFormat='RG: {0}'}" />
      <Label Text="{Binding Aluno.CPF, StringFormat='CPF: {0}'}" />
    </StackLayout>
    <Label Text="Contato" Grid.Row="1" Grid.Column="0" BackgroundColor="Gray" Grid.ColumnSpan="2"></Label>
    <Label Text="{Binding Aluno.Email}" Grid.Row="2" Grid.Column="0"></Label>
    <ListView ItemsSource="{Binding Aluno.Telefones}"  Grid.Row="3" Grid.Column="0">
      <ListView.ItemTemplate>
        <DataTemplate>
          <ViewCell>
            <StackLayout Orientation="Horizontal">
              <Label Text="{Binding Tipo, StringFormat='{0}: '}"></Label>
              <Label Text="{Binding Telefone}"></Label>
            </StackLayout>
          </ViewCell>
        </DataTemplate>
      </ListView.ItemTemplate>
    </ListView>
    <Label Text="Endereço Residencial" Grid.Row="4" Grid.Column="0" BackgroundColor="Gray" Grid.ColumnSpan="2"></Label>
    <StackLayout Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2">
      <Label Text="{Binding Aluno.EnderecoResidencial.Logradouro}" />
    </StackLayout>
  </Grid>
</ContentPage>

This is the View Model:

public class DadosCadastraisVM : Model.ObservableBase
    {
        private AlunoModel _aluno;

        public AlunoModel Aluno
        {
            get { return _aluno; }
            set
            {
                _aluno = value;
                OnPropertyChanged();
            }
        }

        public DadosCadastraisVM()
        {
            Aluno = new AlunoModel
            {
                Nome = "Aluno Teste",
                DataNascimento = new DateTime(2000, 08, 04),
                RG = "23.588.555-45",
                CPF = "111.222.333-44",
                Email = "[email protected]",
                Telefones = new ObservableCollection<TelefoneModel>
                {
                    new TelefoneModel {Tipo = "Celular", Telefone = "(11) 99009-8899" },
                    new TelefoneModel { Tipo = "Residencial", Telefone = "(11) 4499-2233" }
                },
                EnderecoComercial = new Endereco
                {
                    Logradouro = "Rua teste",
                    Numero = "2937",
                    Bairro = "Bairro teste",
                    Cidade = "São paulo",
                    Estado = "SP",
                    Cep = "02233-223",
                    Complemento = string.Empty
                },
                EnderecoResidencial = new Endereco
                {
                    Logradouro = "Rua teste",
                    Numero = "2937",
                    Bairro = "Bairro teste",
                    Cidade = "São paulo",
                    Estado = "SP",
                    Cep = "02233-223",
                    Complemento = string.Empty                    }
            };
        }
    }

This is the Student class with the Address and Phone classes:

public class AlunoModel
    {
        public string Nome { get; set; }
        public DateTime DataNascimento { get; set; }
        public string RG { get; set; }
        public string CPF { get; set; }
        public string Email { get; set; }
        public ObservableCollection<TelefoneModel> Telefones { get; set; }
        public Endereco EnderecoComercial { get; set; }
        public Endereco EnderecoResidencial { get; set; }
    }

public class TelefoneModel
    {
        public string Tipo { get; set; }
        public string Telefone { get; set; }
    }

public class Endereco
    {
        public string Logradouro { get; set; }
        public string Numero { get; set; }
        public string Bairro { get; set; }
        public string Cep { get; set; }
        public string Cidade { get; set; }
        public string Estado { get; set; }
        public string Complemento { get; set; }
    }
    
asked by anonymous 08.03.2017 / 11:39

0 answers