UWP VirtualizedVariableSizedGridView 支持可虚拟化可变大小Item的View(一)
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(一)的更多相关文章
- UWP VirtualizedVariableSizedGridView 支持可虚拟化可变大小Item的View(二)
上篇UWP VirtualizedVariableSizedGridView 支持可虚拟化可变大小Item的View(一) 讲到该控件的需要和设计过程. 这篇讲讲开发过程中一些重要问题解决. 1.支持 ...
- 算法Sedgewick第四版-第1章基础-008一用数组实现栈(泛型、可变大小)
package algorithms.ADT; /*************************************************************************** ...
- Xamarin.Forms 现已开启对 UWP 的支持
Xamarin.Forms 现已升级到 2.0.0.6482 , 正式开启了对 UWP 的支持. 要创建 UWP 项目, 必须是 VS2015, WIN8.1 下也可以, 但是只有 Windows 1 ...
- 关于理解《C++ 对象模型》中:把单一元素的数组放在末尾,struct可以拥有可变大小的数组
这一章在第19页,写的好深奥,我竟然没看明白在说什么--之后再看了几遍,终于明白了. 原文: C程序员的巧计有时候却成为c++程序员的陷阱.例如把单一元素的数组放在一个struct的末尾,于是每个st ...
- 64位平台支持大于2 GB大小的数组
64位平台支持大于2 GB大小的数组 64位平台.NET Framework数组限制不能超过2GB大小.这种限制对于需要使用到大型矩阵和向量计算的工作人员来说,是一个非常大问题. 无论RAM容量有多大 ...
- 移动设备应用程序中支持多个屏幕大小和 DPI 值
支持多个屏幕大小和 DPI 值的指导原则 要部署独立于平台的应用程序,应了解不同的输出设备.设备可以具有不同的屏幕大小或分辨率以及不同的 DPI 值或密度. Flex 工程师 Jason SJ 在他的 ...
- 使struct对象拥有可变大小的数组——(C++深度探索)
首先摘录<Inside The C++ Object Model>中的一段话: 把单一元素的数组放在一个struct的尾端,于是每个 struct objects 可以拥有可变大小的数组: ...
- 0x04 Python logger 支持多进程日志按大小分割
目录 支持多进程日志按大小分割 多进程日志大小分割handler配置实例 支持多进程日志按大小分割 由于python内置模块logging.handlers.RotatingFileHandler是不 ...
- 如何查看自己的电脑 CPU 是否支持硬件虚拟化
引言 在你安装各种虚拟机之前,应该先测试一下自己的电脑 CPU 是否支持硬件虚拟化. 如果你的电脑比较老旧,可能不支持硬件虚拟化,那么将无法安装虚拟机软件. 如何查看自己 CPU 是否支持硬件虚拟化 ...
随机推荐
- Linux 命令
Linux 常用命令 su root 切换root用户 touch /etc/www/html/1.txt 创建文件 mkdir /usr/local/apache2 建立文件夹 rm -rf ...
- IntelliJ IDEA mac 快捷键
cmd+O 查找类alt+cmd+O 符号shift+cmd+O 查找文件^+space 补全alt + F7 查找符号的使用情况F1 查看文档cmd+b 跳转定义,或者 鼠标+ctrlcmd+F12 ...
- 把域名绑定到某个项目,以nginx服务器为例
一:登陆域名服务器平台,把域名解析到项目对应的IP上面. 二:配置nginx服务器 1./etc/nginx/conf.d/ 在服务器该目录下,添加.conf文件,如命名为:www.demo.com. ...
- jexus5.8.2 linux x64通用版[未集成mono] 配置https
一.找到mono安装位置 sudo find / -name mono 二.首先查看"/lib"或"/usr/lib"等系统库文件夹中是否有SSL库文件的名字, ...
- gradle多模块开发
参考文档:gradle的官方userguide.pdf文档的chapter 55和chapter 56.gradle的多模块或项目开发一定不会比maven差,在我看来!大的项目分成多个模块来开发是常事 ...
- bootstrap1
让bootstarp3 支持ie的兼容模式: 支持浏览器的响应式布局: 是指网页既可以用在pc上,也可以用在手机上, 而且不需要修改源文件. bootstrap包括: css文件, 只需要加载: cs ...
- CAS环境搭建
实验背景: 系统环境: Windows XP | SUN JDK1.6U4 | Tomcat6.0.14 | CAS Server 3.1.1 + CAS Client 2.1.1 主机完整名称: ...
- Linux系统硬链接和软链接介绍
1.链接的概念 在Linux系统中链接分为硬链接和软连接两种,一种为硬链接,另一种为软连接或符号链接(symbolic Link).ln命令就是创建链接文件的,在默认不带参数的情况下,执行ln命令创建 ...
- 关于TCP中的MSS
MSS 是TCP选项中最经常出现,也是最早出现的选项.MSS选项占4byte.MSS是每一个TCP报文段中数据字段的最大长度,注意:只是数据部分的字段,不包括TCP的头部.TCP在三次握手中,每一方都 ...
- Java 中正确获取中文字符串长度
/** * 获取字符串的长度,如果有中文,则每个中文字符计为2位 * * @param value * 指定的字符串 * * @return 字符串的长度 */ public static int l ...