Windows runtime WinRT中使用MVVMCross增量加载GridView

Windows runtime WinRT中使用MVVMCross增量加载GridView,windows-runtime,mvvmcross,Windows Runtime,Mvvmcross,在使用WinRT时,我很难找到一种实现GridView增量加载的方法 文档仅指定了一种方法,用于在WinRT中执行增量加载—绑定到实现ISupportIncrementalLoading的集合。但是,可移植类库中不存在此接口 我想知道是否有可能将viewmodels保留在核心PCL中,并且仍然实现增量加载?当PCL配置文件中不存在接口时,一种前进的方法是将接口复制到PCL中,然后使用ValueConverter将接口包装并调整为其本机等效接口 这适用于小型接口-类似于MvvmCross如何将IV

在使用WinRT时,我很难找到一种实现GridView增量加载的方法

文档仅指定了一种方法,用于在WinRT中执行增量加载—绑定到实现ISupportIncrementalLoading的集合。但是,可移植类库中不存在此接口


我想知道是否有可能将viewmodels保留在核心PCL中,并且仍然实现增量加载?

当PCL配置文件中不存在接口时,一种前进的方法是将接口复制到PCL中,然后使用ValueConverter将接口包装并调整为其本机等效接口

这适用于小型接口-类似于MvvmCross如何将
IValueConverter
本身变成便携式接口

因此,是的,可以在PCL中实现ViewModel,并且本地UI可以通过适配器使用不可移植的接口

但是,如果您需要整理/调整较大的对象,则上述过程可能有点繁琐,例如,如果您需要整理
ISupportIncrementalLoading
,以及其他接口,如
IEnumerable
ICollection
,等等

在这种情况下,将“ViewModel”移出到非PCL代码中可能更容易

通常,我会将集合放入非PCL代码中,例如:

  • 声明可移植的
    IMyIncrementalCollectionFactory
    IMyIncrementalCollection
    接口类似于:

    public interface IMyIncrementalCollectionFactory
    {
        IMyIncrementalCollection<T> Create();
    }
    
    public interface IMyIncrementalCollection<T>
    {
        event EventHandler<RequireMore<T>> OnRequireMore;
        void SetHasMore(bool value);
    }
    
    公共接口IMyIncrementalCollectionFactory
    {
    IMyIncrementalCollection Create();
    }
    公共接口IMyIncrementalCollection
    {
    事件处理程序OnRequireMore;
    void SetHasMore(布尔值);
    }
    
  • 使用一个集合类在WinRT中实现
    IMyIncrementalCollection
    ,该集合类将
    LoadMoreItemsAsync
    调用映射到
    OnRequireMore
    事件中

  • 使用返回上述集合实例的类在WinRT中实现
    IMyIncrementalCollectionFactory

  • 编写我的页面级视图模型以使用
    IMyIncrementalCollectionFactory
    创建集合


  • 同样的过程可以让我在共享代码中保留“加载更多”逻辑本身。

    当pcl配置文件中不存在接口时,一种前进的方法是将接口复制到pcl中,然后使用ValueConverter将接口包装并调整为其本机等效接口

    这适用于小型接口-类似于MvvmCross如何将
    IValueConverter
    本身变成便携式接口

    因此,是的,可以在PCL中实现ViewModel,并且本地UI可以通过适配器使用不可移植的接口

    但是,如果您需要整理/调整较大的对象,则上述过程可能有点繁琐,例如,如果您需要整理
    ISupportIncrementalLoading
    ,以及其他接口,如
    IEnumerable
    ICollection
    ,等等

    在这种情况下,将“ViewModel”移出到非PCL代码中可能更容易

    通常,我会将集合放入非PCL代码中,例如:

  • 声明可移植的
    IMyIncrementalCollectionFactory
    IMyIncrementalCollection
    接口类似于:

    public interface IMyIncrementalCollectionFactory
    {
        IMyIncrementalCollection<T> Create();
    }
    
    public interface IMyIncrementalCollection<T>
    {
        event EventHandler<RequireMore<T>> OnRequireMore;
        void SetHasMore(bool value);
    }
    
    公共接口IMyIncrementalCollectionFactory
    {
    IMyIncrementalCollection Create();
    }
    公共接口IMyIncrementalCollection
    {
    事件处理程序OnRequireMore;
    void SetHasMore(布尔值);
    }
    
  • 使用一个集合类在WinRT中实现
    IMyIncrementalCollection
    ,该集合类将
    LoadMoreItemsAsync
    调用映射到
    OnRequireMore
    事件中

  • 使用返回上述集合实例的类在WinRT中实现
    IMyIncrementalCollectionFactory

  • 编写我的页面级视图模型以使用
    IMyIncrementalCollectionFactory
    创建集合

  • 同样的过程也会让我在共享代码中保留“加载更多”逻辑本身