/// <summary> /// <para>Constructor of Collection View</para> /// <para>构造函数</para> /// </summary> /// <param name="items"><para>Initialing Items</para><para>初始内容集合</para></param> /// <param name="groupCollection"><para>Initaling Groups</para><para>初始分组</para></param> public CollectionView( IEnumerable <T> items, CollectionViewGroupCollection <T> groupCollection) : base(items.ToArray()) { _group = groupCollection; if (_group != null && items != null) { foreach (var item in items) { _group.AddItemToGroups(item); } } }
public void InitData(CollectionViewType type) { var rnd = new Random(); var grps = Enumerable.Range(0, 100) .Select(i => new { Index = i, Item = new TreeViewItemModel <string> { Value = "Item_" + i.ToString() } }) .GroupBy(itm => (int)(itm.Index / 10)) .Select(grp => new TreeViewItemModel <string> { Value = "Group " + grp.Key.ToString(), Children = new ObservableCollection <ITreeItem <object, TreeViewItemState> >( grp.Select(gi => gi.Item) ) }).ToArray(); var items = grps.SelectMany(x => x.Children.Select(c => { var mc = c as TreeViewItemModel <string>; if (mc != null) { mc.Parent = x; } return(mc); })); switch (type) { case CollectionViewType.Normal: CollectionView = new CollectionView <TreeViewItemModel <string> >(items); break; case CollectionViewType.Loading: var loader = new CollectionViewIncrementalLoader <TreeViewItemModel <string> > ( async(cv, cnt) => { return(new IncrementalLoadResult <TreeViewItemModel <string> > { HaveMore = true, NewItems = Enumerable.Range(0, cnt) .Select( i => new TreeViewItemModel <string> { Value = "New_" + i.ToString(), Parent = grps[i % 10] } ) .ToArray() }); }, (cv) => true ); CollectionView = new CollectionView <TreeViewItemModel <string> >(items, loader); break; case CollectionViewType.Grouped: var igrps = CollectionViewGroupCollection <TreeViewItemModel <string> > .Create( x => x.Parent, x => x.Parent); CollectionView = new CollectionView <TreeViewItemModel <string> >(items, igrps); break; default: break; } }