ISupportIncrementalLoading Windows Phone

时间:2015-05-05 14:19:31

标签: c# xaml pagination windows-phone-8.1

我正在开发一个Windows Phone 8.1应用程序,该应用程序将使用ISupportIncrementalLoading上的GridView。 但是我尝试了多个教程:

我似乎无法弄清楚如何让它正常工作。

api适用于分页: 我有一个模型包裹着我用作ItemsSource的对象。

public class ResponseGetProducts : ObservableObject
{        
    public ResponseGetProduct[] products { get; set; } //the bindable property  
    public uint pages { get; set; } //amount of pages in total
}

不知道它是否相关但ResponseGetProduct - 类

public class ResponseGetProduct : ObservableObject
{
    public int Id { get; set; }
    public long remote_id { get; set; }
    public string name { get; set; }
    public string description { get; set; }
    public double price { get; set; }
    public string remote_page { get; set; }
    public uint status { get; set; }
    public long[] related_ids { get; set; }
    public ResponseImage[] images { get; set; }
}

在我的ViewModel中,我有一个属性

private IncrementalResponseList _ginsIncrementalResponseList;
public IncrementalResponseList GinsIncrementalResponseList
{
    get
    {
       return new IncrementalResponseList();
    }
    set
    {
        Set(() => GinsIncrementalResponseList, ref _ginsIncrementalResponseList, value);
    }
}

在我的XAML中我有

<GridView
    ItemsSource="{Binding GinsIncrementalResponseList}"
    ... />

如何在滚动时使用ISupportIncrementalLoading - 界面使列表从页面添加项目?

我用伪代码制作了这个:

public class IncrementalResponseList : ObservableCollection<ResponseGetProduct>, ISupportIncrementalLoading
{

    public IncrementalResponseList()
    {

    }

    public bool HasMoreItems
    {
        get
        {
            //true if the count of the pages has not been reached;
            pageID++; //up the current page
        }
    }

    public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
    {
        CoreDispatcher dispatcher = Window.Current.Dispatcher;

        return Task.Run<LoadMoreItemsResult>(() =>
        {
            dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                var result = await _service.GetAllGins(pageID); //method to fetch the products
                foreach (var product in result.products)
                {
                    Add(product);
                }
            });


            return new LoadMoreItemsResult() { Count = //the api returns a maximum of 3 items per page. };
        }).AsAsyncOperation<LoadMoreItemsResult>();
    }
}

0 个答案:

没有答案