试图在我的xamarin android(Mvvmcross)上使用Infinite Scroll Plugin

时间:2017-02-06 09:02:54

标签: android xamarin mvvmcross

问题是它抛出了异常

  

“无法构造和初始化ViewModel”

但如果我从GitHub https://github.com/HBSequence/Sequence下载示例。插件有效。

我的 MainViewModel

 private readonly IIncrementalCollectionFactory  _incrementalCollectionFactory;

    private readonly int _numberListPageSize = 30;
    private ObservableCollection<NumberViewModel> _numbers;

    public MainViewModel(IIncrementalCollectionFactory incrementalCollectionFactory)
    {
        _incrementalCollectionFactory = incrementalCollectionFactory;
    }

    public ObservableCollection<NumberViewModel> Numbers
    {
        get
        {
            if (_numbers == null)
            {
                //async (count, pageSize) 
                // The IncrementalCollectionFactory returns a generic ObservableCollection. In this example, 
                // it returns ObservableCollection<NumberViewModel>. Replace this with your own ViewModel.

                _numbers = _incrementalCollectionFactory.GetCollection(async (count,pageSize)=>
                {
                    ObservableCollection<NumberViewModel> newNumbers = new ObservableCollection<NumberViewModel>();

                    // Call an async method here to load the data from a data source that supports paging.
                    // This is a dummy implementaion.

                    await Task.Run(() =>
                   {
                        for (int n = count; n < (count + pageSize); n++)
                        {
                            NumberViewModel numberViewModel = new NumberViewModel();
                            numberViewModel.Value = n;
                            newNumbers.Add(numberViewModel);
                        }
                    });

                    //var pagedNewsEntities = await _newsInteractor.GetNewsAsync(pageSize);

                    return newNumbers;
                }, _numberListPageSize);
            }

            return _numbers;
        }
    }
}                                                               

0 个答案:

没有答案