I am making a ListView
inside my C # file. But instead, I want to add the data I get from sqlite, also a data-bound xaml file, so I can still edit the layout using xaml. Therefore, each response from sqlite should be added as a label ( <TextCell Text="{Binding Name}" />
).
My question is: how can I bind a response from GetCategoryByMenuID
to TextCell Text="{Binding Name}"
?
xaml page (CategoriePage.xaml):
<?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="AmsterdamTheMapV3.CategoriePage"> <ListView x:Name="listView"> <ListView.ItemTemplate> <DataTemplate> <TextCell Text="{Binding Name}" /> </DataTemplate> </ListView.ItemTemplate> </ListView> </ContentPage>
Back-end / C # (CategoriePage.xaml.cs):
namespace AmsterdamTheMapV3 { public partial class CategoriePage : ContentPage { public CategoriePage(String txt) { InitializeComponent(); var layout = new StackLayout { Padding = new Thickness(5, 10) }; int page = Int32.Parse(txt); this.Content = layout; var categories = App.Database.GetCategoryByMenuID(page); var datatemplate = new DataTemplate(() => { var nameLabel = new Label(); nameLabel.SetBinding(Label.TextProperty, "Name");
GetCategoryPage Function:
public List<Categories> GetCategoryByMenuID(int menuID) { lock (locker) { return db.Table<Categories>().Where(x => x.Menu_ID == menuID).ToList(); } }
source share