2
respostas

Minha Lista Aparece Nula

public class Post
    {
        private String nome;
        private String conteudo;

        public Post(string nome, string conteudo)
        {
            this.nome = nome ?? throw new ArgumentNullException(nameof(nome));
            this.conteudo = conteudo ?? throw new ArgumentNullException(nameof(conteudo));
        }

        public string Nome { get => nome; set => nome = value; }

        public string Conteudo { get => conteudo; set => conteudo = value; }

        public override string ToString()
        {
            return nome +":" + conteudo;
        }
    }

==========================================================

  public partial class MainPage : ContentPage
{

        public List<Post> Posts;

        public MainPage()
        {
            InitializeComponent();

            Posts = new List<Post> {
                new Post("Sigmundo", "Tragam o material impresso"),
                new Post("Carrard", "Hoje vai ser só lagrimas"),
                new Post("Wanderley", "Teremos uma simples lista de exercícios só pra brincar"),
                new Post("Rodrigo", "Hoje teremos a aula do soninho"),
            };

            this.BindingContext = this;
        }
}

==========================================================


<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:Avantis"
             x:Class="Avantis.MainPage">

    <ListView x:Name="Feed" ItemsSource="{Binding Posts}" Margin="20">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                        <StackLayout>
                            <Label Text="{Binding Nome}" FontSize="Medium" VerticalTextAlignment="Center"></Label>
                            <Label Text="{Binding Conteudo}" FontSize="Small" VerticalTextAlignment="Center"></Label>
                        </StackLayout>
                    </ViewCell.View>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage>
2 respostas

Só colocar Get e Set =)

 public List<Post> Posts { get; set; }

Eu estava me preparando para escrever o mesmo, obrigado, Vilson!

Emmanuel, consegue resolver o problema com get e set na propriedade Posts?