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 类来做这个分割。

internal class RowAdapter<T> : IList<IEnumerable<T>>, ISupportIncrementalLoading
{
private readonly IList<T> items;
public readonly int rowItemsCount; public IList<T> SourceList
{
get { return items; }
} public RowAdapter(IList<T> sourceList, int rowItemsCount)
{
if (null == sourceList)
throw new ArgumentNullException("sourceList", "sourceList can not be null");
if (rowItemsCount <= )
throw new 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<IEnumerable<T>> Members public int IndexOf(IEnumerable<T> item)
{
var realItem = item as RowObject<T>;
if (null == realItem || !ReferenceEquals(realItem.Parent, this))
return -; // It does not belong to this collection Debug.Assert( == realItem.StartIndex % rowItemsCount, "RowObject item has a wierd index");
return realItem.StartIndex / rowItemsCount;
} public void Insert(int index, IEnumerable<T> item)
{
throw new NotSupportedException();
} public IEnumerable<T> this[int index]
{
get
{
if (index < || index > Count)
return null; return InternalGetRow(index);
}
set
{
throw new NotSupportedException();
}
} public void RemoveAt(int index)
{
throw new NotSupportedException();
} #endregion #region ICollection<IEnumerable<T>> Members public void Add(IEnumerable<T> item)
{
throw new NotSupportedException();
} public bool Contains(IEnumerable<T> item)
{
var realItem = item as RowObject<T>;
return null != realItem && object.ReferenceEquals(realItem.Parent, this);
} public void CopyTo(IEnumerable<T>[] array, int arrayIndex)
{
// I haven't implemented this. It is easy to implement if you need it
throw new NotImplementedException();
} public bool Remove(IEnumerable<T> item)
{
throw new NotSupportedException();
}
public void Clear()
{
throw new NotSupportedException();
} public int Count
{
get
{
return (items.Count + (rowItemsCount - )) / rowItemsCount;
}
} public bool IsReadOnly
{
get { return true; }
} public bool HasMoreItems
{
get
{
if (items is ISupportIncrementalLoading)
{
return (items as ISupportIncrementalLoading).HasMoreItems;
}
return false;
}
} #endregion #region IEnumerable<IEnumerable<T>> Members public IEnumerator<IEnumerable<T>> GetEnumerator()
{
for (int i = ; i < Count; ++i)
{
yield return InternalGetRow(i);
}
} #endregion #region IEnumerable Members System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
} #endregion private RowObject<T> InternalGetRow(int index)
{
return new RowObject<T>(this, index * rowItemsCount);
} public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
{
if (items is ISupportIncrementalLoading)
{
IAsyncOperation<LoadMoreItemsResult> result = (items as ISupportIncrementalLoading).LoadMoreItemsAsync(count);
return result;
} return null;
}
}

可以看到这个类的构造

public RowAdapter(IList<T> sourceList, int rowItemsCount)

sourceList就是源数据,而rowItemsCount就是每个GirdView里面源的个数。

到这里我们就解决了,整个控件的大体思路以及源的处理,下一篇会讲讲该开发中一些重要问题的解决。
有问题的朋友可以留言,或者查看GitHub源码

UWP VirtualizedVariableSizedGridView 支持可虚拟化可变大小Item的View(一)的更多相关文章

  1. UWP VirtualizedVariableSizedGridView 支持可虚拟化可变大小Item的View(二)

    上篇UWP VirtualizedVariableSizedGridView 支持可虚拟化可变大小Item的View(一) 讲到该控件的需要和设计过程. 这篇讲讲开发过程中一些重要问题解决. 1.支持 ...

  2. 算法Sedgewick第四版-第1章基础-008一用数组实现栈(泛型、可变大小)

    package algorithms.ADT; /*************************************************************************** ...

  3. Xamarin.Forms 现已开启对 UWP 的支持

    Xamarin.Forms 现已升级到 2.0.0.6482 , 正式开启了对 UWP 的支持. 要创建 UWP 项目, 必须是 VS2015, WIN8.1 下也可以, 但是只有 Windows 1 ...

  4. 关于理解《C++ 对象模型》中:把单一元素的数组放在末尾,struct可以拥有可变大小的数组

    这一章在第19页,写的好深奥,我竟然没看明白在说什么--之后再看了几遍,终于明白了. 原文: C程序员的巧计有时候却成为c++程序员的陷阱.例如把单一元素的数组放在一个struct的末尾,于是每个st ...

  5. 64位平台支持大于2 GB大小的数组

    64位平台支持大于2 GB大小的数组 64位平台.NET Framework数组限制不能超过2GB大小.这种限制对于需要使用到大型矩阵和向量计算的工作人员来说,是一个非常大问题. 无论RAM容量有多大 ...

  6. 移动设备应用程序中支持多个屏幕大小和 DPI 值

    支持多个屏幕大小和 DPI 值的指导原则 要部署独立于平台的应用程序,应了解不同的输出设备.设备可以具有不同的屏幕大小或分辨率以及不同的 DPI 值或密度. Flex 工程师 Jason SJ 在他的 ...

  7. 使struct对象拥有可变大小的数组——(C++深度探索)

    首先摘录<Inside The C++ Object Model>中的一段话: 把单一元素的数组放在一个struct的尾端,于是每个 struct objects 可以拥有可变大小的数组: ...

  8. 0x04 Python logger 支持多进程日志按大小分割

    目录 支持多进程日志按大小分割 多进程日志大小分割handler配置实例 支持多进程日志按大小分割 由于python内置模块logging.handlers.RotatingFileHandler是不 ...

  9. 如何查看自己的电脑 CPU 是否支持硬件虚拟化

    引言 在你安装各种虚拟机之前,应该先测试一下自己的电脑 CPU 是否支持硬件虚拟化. 如果你的电脑比较老旧,可能不支持硬件虚拟化,那么将无法安装虚拟机软件. 如何查看自己 CPU 是否支持硬件虚拟化 ...

随机推荐

  1. 关于MySQL存储过程中遇到的一个错误

    执行结果: 查询:)) comment '操作变量' begin set var='MySQL%Orcle%DeLL%IBM'; select replace(var,'%'... 共 行受到影响 执 ...

  2. Unity3D Editor 扩展

    官方教程:链接 EditorLayout API:链接 Handles API:链接 1.首先来个Inspector面板Editor的实现 要实现一个组件在Inspector中的Editor功能,首先 ...

  3. 转→js数组遍历 千万不要使用for...in...

    看到一篇内容还不错,但是排版实在糟糕, 逼死强迫症患者啊,直接拉下去找原文连接,找到了,但是已经消失了···500错误... 第一次因为实在看不下去一篇博客的排版, 为了排版而转载... 转载地址:h ...

  4. WebClient 实现多文件/文本同时上传

    public class CreateBytes { Encoding encoding = Encoding.UTF8; /**/ /// <summary> /// 拼接所有的二进制数 ...

  5. From 202.97.60.193 icmp_seq=48 Time to live exceeded

    从浙江某电信ip的服务器上 ping 大陆外某个外网地址不通,报如下信息: From 202.97.60.193 icmp_seq=48 Time to live exceeded google,百度 ...

  6. 常用ADO.NET操作ACCESS数据库

    using System; using System.Collections.Generic; using System.Text; using System.Data;// using System ...

  7. Gulp真实项目用例

    包括了less预编译,css压缩,html文件include引入,js混淆压缩,本地开发热刷新服务器,html压缩,版本号添加 github地址: gulpfile.js var gulp = req ...

  8. 用Xcode 安装ipa,查看程序资源文件夹

    Xcode中的Devices工具就能够提供以上2项功能,不需要安装其他第三方工具了,见下面的截图:

  9. 【python】安装指定模块

    使用pip 1.卸载模块 sudo pip uninstall xxx 2.安装指定版本模块 sudo pip install xxx==2.0.1.3

  10. 切换debian8系统语言环境

    想切换操作系统的默认语言环境,可以使用如下命令,而不用重新安装系统: 查看操作系统的语言: # env | grep LANG 使用root导入要使用的系统语言: # export LANG=en_U ...