本篇文章主要介绍了" UWP VirtualizedVariableSizedGridView 支持可虚拟化可变大小Item的View(一)",主要涉及到方面的内容,对于.NETjrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下:
Boss的需要时这样的,Item是可变大小的,同时根据不同的Window size,来确定Item的结构和大小Window 小的时候是大的时候是这样的:当然这s...
Boss的需要时这样的,Item是可变大小的,同时根据不同的Window size,来确定Item的结构和大小
Window 小的时候是

大的时候是这样的:

当然这size变化的过程中也允许其他结构,我这里只是举了最大和最小时候的样子。
当拿到需求的时候,相信大家肯定第一想到的是,将GirdView的ItemsPanel改成VariableSizedWrapGrid。
VariableSizedWrapGrid是怎么样用的,不知道的童鞋点击先行脑补下.官方文档 diederik的sample
嗯,效果就这样的,差不多。。。是这样的吗??
仔细的朋友可以看到了这段话:
The content of a VariableSizedWrapGrid is not virtualized. This can reduce performance when you work with large data sets. For more info, see Optimize ListView and GridView.
哦,no。这个东西不支持虚拟化。。
Google了下,嗯。各种网上问的,但是没有解决办法。想想也是,这种结构,是很难计算出Items的总高度或者总宽度的。
本着我不下地狱谁下地狱的原则,既然没人搞出来,就让我来造福大众吧。。。我疯狂的上网搜索,自己也想过一些办法,但都被自己推倒了。(太软,易推倒)
吃晚饭的时候突然灵光一现,嗯,想出了下面的结构:
ListView的每个Item是个GridView,而将GirdView的ItemsPanel改成VariableSizedWrapGrid。
自己写了个简单的sample,稍微搞了些,可行。
数据结构应该是这样的:
比如一共有150个Item,15个元素为一组作为每个GridView的源来组成可变大小结构。
现在的问题来了,怎么样才能方便的把原始的数据结构转变为我想要的那种呢??
方法是写一个IList 类来做这个分割。


internalclass RowAdapter : IList<>>, ISupportIncrementalLoading
{
privatereadonly IList items;
publicreadonlyint rowItemsCount;
public IList SourceList
{
get { return items; }
}
public RowAdapter(IList sourceList, int rowItemsCount)
{
if (null == sourceList)
thrownew ArgumentNullException("sourceList", "sourceList can not be null");
if (rowItemsCount <= 0)
thrownew ArgumentOutOfRangeException("rowItemsCount", "rowItemsCount should be more than one");
// We require the source list to implement IList because we
// need to know how many item there are items = sourceList;
this.rowItemsCount = rowItemsCount;
}
#region IList<>> Members
publicint IndexOf(IEnumerable item)
{
var realItem = item as RowObject;
if (null == realItem || !ReferenceEquals(realItem.Parent, this))
return -1; // It does not belong to this collection Debug.Assert(0 == realItem.StartIndex % rowItemsCount, "RowObject item has a wierd index");
return realItem.StartIndex / rowItemsCount;
}
publicvoid Insert(int index, IEnumerable item)
{
thrownew NotSupportedException();
}
public IEnumerable this[int index]
{
get {
if (index < 0 || index > Count)
returnnull;
return InternalGetRow(index);
}
set {
thrownew NotSupportedException();
}
}
publicvoid RemoveAt(int index)
{
thrownew NotSupportedException();
}
#endregion#region ICollection<>> Members
publicvoid Add(IEnumerable item)
{
thrownew NotSupportedException();
}
publicbool Contains(IEnumerable item)
{
var realItem = item as RowObject;
returnnull != realItem && object.ReferenceEquals(realItem.Parent, this);
}
publicvoid CopyTo(IEnumerable[] array, int arrayIndex)
{
// I haven't implemented this. It is easy to implement if you need itthrownew NotImplementedException();
}
publicbool Remove(IEnumerable item)
{
thrownew NotSupportedException();
}
publicvoid Clear()
{
thrownew NotSupportedException();
}
publicint Count
{
get {
return (items.Count + (rowItemsCount - 1)) / rowItemsCount;
}
}
publicbool IsReadOnly
{
get { returntrue; }
}
publicbool HasMoreItems
{
get {
if (items is ISupportIncrementalLoading)
{
return (items as ISupportIncrementalLoading).HasMoreItems;
}
returnfalse;
}
}
#endregion#region IEnumerable<>> Members
public IEnumerator<>> GetEnumerator()
{
for (int i = 0; i < Count; ++i)
{
yieldreturn InternalGetRow(i);
}
}
#endregion#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregionprivate RowObject InternalGetRow(int index)
{
returnnew RowObject(this, index * rowItemsCount);
}
public IAsyncOperation LoadMoreItemsAsync(uint count)
{
if (items is ISupportIncrementalLoading)
{
IAsyncOperation result = (items as ISupportIncrementalLoading).LoadMoreItemsAsync(count);
return result;
}
returnnull;
}
}
View Code可以看到这个类的构造
public RowAdapter(IList sourceList, int rowItemsCount)
sourceList就是源数据,而rowItemsCount就是每个GirdView里面源的个数。
到这里我们就解决了,整个控件的大体思路以及源的处理,下一篇会讲讲该开发中一些重要问题的解决。
有问题的朋友可以留言,或者查看GitHub源码
以上就介绍了 UWP VirtualizedVariableSizedGridView 支持可虚拟化可变大小Item的View(一),包括了方面的内容,希望对.NETjrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_1657774.html