We are developing an iOS shopping cart application in C#
, Visual Studio 2017
with Xamarin
. We are using rest web services and I'm having some trouble with Data Bindings
:
How do I bind content page(children of the tabbed page) title as well as listview in the tabbed page?
Now tabbed page working fine but listview is not working, Request you to help us to resolve this issue and we are pasting the code below
TabbedPage1.xaml.cs
namespace SalesRep.SalesOrderPages
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class TabbedPage1 : TabbedPage
{
ObservableCollection<Class1> Filter = new ObservableCollection<Class1>();
public TabbedPage1()
{
InitializeComponent();
}
protected async override void OnAppearing()
{
base.OnAppearing();
var lst = await App.TodoManager.GetItemTasksAsync("all");//this is catalog list from rest | var MyTabTitle = await App.TodoManager.GetEmployeeTasksAsync("Roudy");//this is Salerep Employee list from rest
var myArray = MyTabTitle.ToArray<Employee>();
var arraycount = MyTabTitle.Count;
int arraypos = 0;
RootObject2 rs = new RootObject2();
foreach (var i in lst)
{
var hai = JsonConvert.SerializeObject(i);
var myitem = JsonConvert.DeserializeObject<RootObject2>(hai);
var lst1 = new Class1 // Here i have created Class1 which i display tab title and cataloge item
{
FilterName=myArray[arraypos].FilterName,
Items= myitem.Catalog
};
if (arraypos < arraycount -1)
arraypos = arraypos + 1;
else
break;
Filter.Add(lst1);
}
ItemsSource = Filter;
}
}
}
TabbedPage1.xaml
<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SalesRep.SalesOrderPages.TabbedPage1"
x:Name="MyTab" >
<TabbedPage.ItemTemplate>
<DataTemplate>
<ContentPage Title="{Binding FilterName}">
<StackLayout>
<ListView x:Name="MyListView"
ItemsSource="{Binding Items}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Label Text="{Binding Name}"
FontSize="15"
TextColor="Black" />
<Label Text="{Binding Price, StringFormat='{0:N}'}"
FontSize="15"
TextColor="Black" />
<Label Text="{Binding Pack}"
FontSize="15"
TextColor="Black" />
<Label Text="{Binding UnitPrice}"
WidthRequest="120"
FontSize="15"
TextColor="Black" />
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
</DataTemplate>
</TabbedPage.ItemTemplate>
</TabbedPage>
Employee class used to display dynamic tabbed page from rest api
public class Employee
{
public string EmployeeId { get; set; }
public string FilterName { get; set; }
public string FilterCriteria { get; set; }
}
Cataloge class
namespace SalesRep.Models
{
public class Catalogcls: INotifyPropertyChanged
{
public string Type { get; set; }
public string Image { get; set; }
public string Name { get; set; }
public string UnitPrice { get; set; }
public double Price { get; set; }
public string Pack { get; set; }
}
public class RootObject2
{
public ObservableCollection<Catalogcls> Catalog { get; set; }
}
}
Class 1
namespace SalesRep.Models
{
public class Class1
{
public string FilterName { get; set; }
public ObservableCollection<Catalogcls> Items { get; set; }
}
}