Popular Listview UWP C#

Asked

Viewed 82 times

1

I’m using a bank in sqlite, already done and with data in my application UWP and trying to display in a listview the data in the table Marcas.

What I’ve done so far is create a class Marcas:

public class Marcas
{
    public string Nome { get; set; }
    public string Imagem { get; set; }
    public string Descricao { get; set; }

}

I created a listview onscreen

<ListView x:Name="listView"  HorizontalAlignment="Left" 
          Height="800" VerticalAlignment="Top" Width="500">
        <ListView.Header>
            <StackPanel Height="100" Width="100">
                <TextBlock Text="{Binding Nome}"/>
                <TextBlock Text="{Binding Imagem}"/>
                <TextBlock Text="{Binding Descricao}"/>
            </StackPanel>
        </ListView.Header>
</ListView>

The estate:

public ObservableCollection<Marcas> obs_Marcas { get; set; }

and the method to get the bank records:

 List<Marcas> oMarcas = conn.Query<Marcas>("Select * From Marcas");

 obs_Marcas = new ObservableCollection<Marcas>();
 foreach (Marcas marca in oMarcas)
 {
     obs_Marcas.Add(new Marcas { Nome = marca.Nome, 
                                 Descricao = marca.Descricao, 
                                 Imagem = marca.Imagem 
                                }
                    );
 }
 listView.ItemsSource = obs_Marcas;

Debugging, the object obs_Marcas is filled in correctly with the database data. At the time of the obs_Marcas.Add, name, description and image are being filled in correctly, but in the application the list gets all the records as GeraBanner.Marcas.

What I did wrong and how to display the data correctly?

  • https://social.msdn.microsoft.com/Forums/en-US/b6099324-e66c-42ef-9bfe-a0f022e2b6ab/twoway-binding-working-on-strings-but-not-on-datetimes-and-int-release-preview?forum=winappswithcsharp

1 answer

0


The layout used that is with problems, posted one that may be a layout recommended for your problem and will bring the information in each separate block:

<ListView x:Name="listView"  HorizontalAlignment="Left" 
          Height="800" VerticalAlignment="Top" Width="500">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Height="100" Width="100">
                <TextBlock Text="{Binding Nome}"/>
                <TextBlock Text="{Binding Imagem}"/>
                <TextBlock Text="{Binding Descricao}"/>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>           
</ListView>

Reference:

  • oops, that’s right, you can explain to me what was wrong?

  • @Marceloawq is you put one ListView.Header and the right thing is ListView.ItemTemplate which is intended to show information of a structure ...

Browser other questions tagged

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