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. CDCE913产生任意频率

    1,上TI官网下载CDCE913的datasheet和配置软件clock Pro.如果只需要配置CDCE913成某一个固定频率,那么用clock Pro可以很方便快捷. TI的初衷应该就是通过I2C配 ...

  2. 手机端页面自适应之rem布局

    W3C官网上是这样描述rem的--"font size of the root element" . rem布局在移动端发挥的比较好. 阿里团队高清方案: <script&g ...

  3. WCF学习第二篇:WCF 配置架构。这有助于对wcf配置的理解和记忆

    使用 Windows Communication Foundation (WCF) 配置元素,您可以配置 WCF 服务和客户端应用程序. 可以使用配置编辑器工具 (SvcConfigEditor.ex ...

  4. Java文件操作

    1.通过File类中的createNewFile()创建一个新的文件 /**     * 测试创建文件     * @throws IOException     */    @Test    pub ...

  5. Android 的Parcelable接口

    此文转载自http://www.cnblogs.com/renqingping/archive/2012/10/25/Parcelable.html 1. Parcelable接口 Interface ...

  6. FFT NNT

    算算劳资已经多久没学新算法了,又要重新开始学辣.直接扔板子,跑...话说FFT算法导论里讲的真不错,去看下就懂了. //FFT#include <cstdio> #include < ...

  7. tp中ueditor编辑器的使用

    1/引入三个文件 <script type="text/javascript" charset="utf-8" src="{$Think.con ...

  8. 耿丹CS16-2班助教总结

    Deadline: 2016-1-7 11:59pm 开篇有言 --又是一年末,不似风光,却添风霜,顶霾前进,踽踽独行,可乎? 助教那些事儿 助教这份工作是之前就担任过的,很羞愧,当时才担任了几天就撒 ...

  9. input事件与change事件

    输入框的change事件: 必须等到输入框失去焦点的时候才会触发,鼠标在空白的地方点一下: 输入框的input事件: 在输入内容变化的同时,实时的触发,不需要等到失去焦点.

  10. C#数字日期装换为中文日期

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...