How to bind list inside a list?

TikiTakaTikiTaka Member ✭✭
edited September 13 in Xamarin.Forms

public ~~~~ class Order {

public string CustomerName { get; set; }
    public string InvoiceTitle { get; set; }

public List<OrderItem> OrderItems { get; set; }

}
public class OrderViewModel : BaseViewModel
{
private bool _isBusy;
private const int PageSize = 10;

    public InfiniteScrollCollection<Api.Model.Order.Order> Orders { get; }
    public bool canLoad = true;

    public bool IsBusy
    {
        get => _isBusy;
        set
        {
            _isBusy = value;
            OnPropertyChanged();
        }
    }

    public OrderViewModel()
    {
        Title = "Orders";
        Orders = new InfiniteScrollCollection<Api.Model.Order.Order>
        {
            OnLoadMore = async () =>
            {
                IsBusy = true;

                // load the next page
                var page = Orders.Count / PageSize;

                page++;

                var result =  DataService.GetOrdersAsync(page, PageSize);
                var orders = new List<Api.Model.Order.Order>();
                if (result.Result)
                {
                    orders = result.Response.Data;

                    canLoad = Orders.Count < result.Response.TotalCount;
                }
                IsBusy = false;


                // return the items that need to be added
                return orders;
            },
            OnCanLoadMore = () =>
            {
                return canLoad;
            },

        };

          DownloadDataAsync();
    }
    private async Task DownloadDataAsync()
    {
        var items =  DataService.GetOrdersAsync(pageIndex: 1, pageSize: PageSize);
        Orders.AddRange(items.Response.Data);
    }

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}


 <ListView ItemsSource="{Binding Orders}" CachingStrategy="RecycleElement" HasUnevenRows="True">

            <ListView.Behaviors>
                <extended:InfiniteScrollBehavior IsLoadingMore="{Binding IsBusy}" />
            </ListView.Behaviors>

            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Padding="10,10,5,5">

                                <!--Here I want To bind item from the list but how?-->
                                <Label Text="{Binding OrderItemStatus}" Grid.Row="2" Grid.Column="2" TextColor="CornflowerBlue" FontSize="Medium"/>
                                <Label Text="{Binding IntegrationOrderCode}" Grid.Row="2" Grid.Column="1"/>
                                <!--<Label BackgroundColor="Black" Grid.RowSpan="3" Grid.Column="3"></Label>-->
                                <Image Source="sendIcon.png" Grid.RowSpan="3" Grid.Column="3">
                                    <Image.GestureRecognizers>
                                        <TapGestureRecognizer Tapped="OnSendInvoice"></TapGestureRecognizer>
                                    </Image.GestureRecognizers>
                                </Image>


                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>

        </ListView>

Best Answer

Answers

Sign In or Register to comment.