Holla!
I have created a MAUI android Project and one page is designed sofar like shown below
the xaml behind the table shown at the buttom is simply a gridview with three Listview
<Grid x:Name="GridBill" ColumnDefinitions="*,*,*,*" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0,0.5,1,0.2">
<ListView x:Name="ListInvoice"
BackgroundColor="Bisque"
SeparatorColor="Silver"
Grid.Column="0">
<ListView.Header>
<StackLayout BackgroundColor="Red">
<Label Margin="10,0,0,0"
Text="{x:Static lang:AppResources.ItemName}"
FontSize="12"
FontAttributes="Bold" />
</StackLayout>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label x:Name="NameLabel" Text="{Binding Name}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView x:Name="ListInvoice2"
BackgroundColor="Bisque"
SeparatorColor="Silver"
Grid.Column="1">
<ListView.Header>
<StackLayout BackgroundColor="Red">
<Label Margin="10,0,0,0"
Text="{x:Static lang:AppResources.Price}"
FontSize="12"
FontAttributes="Bold" />
</StackLayout>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Price}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView x:Name="ListInvoice3"
BackgroundColor="Bisque"
SeparatorColor="Silver"
Grid.Column="2">
<ListView.Header>
<StackLayout BackgroundColor="Red">
<Label Margin="10,0,0,0"
Text="{x:Static lang:AppResources.Count}"
FontSize="12"
FontAttributes="Bold" />
</StackLayout>
</ListView.Header>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Count}"/>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
in the page page.xaml.cs I created an internal class and a list of it as shown below
public partial class Sailor : ContentPage
{
List<CollectionItem> items;
internal class CollectionItem
{ public string Name { get; set; }
public string Price { get; set; }
public string Count { get; set; }
}
public Sailor()
{
InitializeComponent();
items = new List<CollectionItem>
{
new CollectionItem{ Name = "xx", Count = "2", Price = "10" },
new CollectionItem{ Name = "zz", Count = "2", Price = "10" }
};
ListInvoice.ItemsSource = items;
ListInvoice2.ItemsSource = items;
ListInvoice3.ItemsSource = items;
}
I built some logic; when Barcode is detected I quest a SQLite DB and get Artice_name and Price and I can print them out when I use console.writeline
Now inorder to add the quested Info in the list view I used this code:
private void CameraView_OnDetectionFinished(object sender, OnDetectionFinishedEventArg e)
{
//play peep
//search in DB
string returnedName = "";
string returnedPrice = "";
var items = await database.GetItemAsync(scannedBarcode);
foreach (var item in items)
{
Console.WriteLine("################");
returnedName = item.Art_Name;
returnedPrice = item.Art_Price.ToString();
}
//add new item to the list
CollectionItem boughtItem = new CollectionItem { Name = returnedName, Count = "1", Price = returnedPrice };
Console.WriteLine(returnedName);
Console.WriteLine(returnedPrice);
Console.WriteLine(boughtItem.Name);
Console.WriteLine(boughtItem.Price);
this.items.Add(boughtItem);
ListInvoice.ItemsSource = items;
ListInvoice2.ItemsSource = items;
ListInvoice3.ItemsSource = items;
});
}
}
}
The issue is, when I scann a barcode and its matching in DB, my code does not update the view list correctely, Nothing happens in xaml UI!
this is the Output from the VS debugger:
I am not sure what I am doing wrong, probably some issue with binding? could you please advice how to refresh the list view sothat it shows the new items each time the list got updated
Cheers! : )