Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Databinding not working in label inside listView

dave_silvadave_silva Member ✭✭

Hello there, I'm using a ListView with interaction with database but currently I'm having a problem while binding some data.

Here's my query on database :

        public async Task<List<Transaction>> GetSpentByCategory()
            return await _database.QueryAsync<Transaction>("SELECT Category,Amount , count(*) as Quantity FROM 'Transaction' WHERE Type = False GROUP BY Category ORDER BY Amount;");

And my xaml :

 <ListView x:Name="listViewSpentByCategory">

                                <StackLayout Orientation="Horizontal">
                                    <StackLayout Orientation="Vertical">

                                        <Label Text="{Binding Category}"
                                TextColor="#000000" />

                                        <Label Text="{Binding Quantity}"
                                TextColor="#000000" />

                                    <Label Text="{Binding Amount}"
                                TextColor="#000000" />

                                    <Label Text="CHF"
                                TextColor="#000000" />





So I can correctly bind Amount and Category, but not Quantity. Do you have any idea why ? Quantity is not a column on my database, that's why my query has "as Quantity".

Best Answer


  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    How is Transaction?
  • dave_silvadave_silva Member ✭✭

    @AlessandroCaliaro said:
    How is Transaction?

    Transaction looks like this in my database.

        public class Transaction
            [PrimaryKey, AutoIncrement]
            public int ID { get; set; }
            public bool Type { get; set; } 
            public string Name { get; set; }
            public string Category { get; set; }
            public float Amount { get; set; }
            public string Date { get; set; }
  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    edited April 18
    You have not a quantity property in this class
  • dave_silvadave_silva Member ✭✭
    > @AlessandroCaliaro said:
    > You have not a quantity property in this class
    Yes but isnt it right using « as Quantity »? If not , how can I bind that value? For the record, I’d like to get number of transactions by category.
Sign In or Register to comment.