积极答复者
请教Bob Bao,关于GridView 数据虚化的问题,GridView的滚动条如果是在最左边的话当,数据源发生变化的时候,GridView是没有内容的?

问题
-
场景:当GridView显示A分类数据的时候,不管当中怎么滑动,只要GridView最后滑动到滚动条的最左端的时候,我再点击B按钮(触发updateView函数)去请求B分类的数据并更新界面,GridView是空的,根本没显示,求解!
主要获取数据以及更新GridView的代码如下:
public async void updateView(int index){
Task<ProductList> task = App.PCProductData.GetProductList(productType[index], 1, order);
ProductList asResult = await task;
iMaxPage = asResult.PageCount;//GetMoreItemFun 是触发LoadMoreItemsOverrideAsync之后调用的方法。
GetMoreItemFun getMoreFun = new GetMoreItemFun(GetProductItemByPage);
//PCDataIncrementClass是继承IncrementalLoadingBase的类
_productPageGroup = new PCDataIncrementClass<SampleDataItem>((uint)iMaxPage, getMoreFun, "");
this.DefaultViewModel["Items"] = _productPageGroup;
}
网络请求数据的委托方法
protected async Task<List<object>> GetProductItemByPage(string strKey, uint page)
{
Task<ProductList> task = App.PCProductData.GetProductList(productType[index], (int)page, order);
ProductList asResult = await task;
return asResult ;
}
继承IncrementalLoadingBase的类
namespace PadClient.DataModel
{
public delegate Task<List<object>> GetMoreItemFun(string strKey, uint page);
// This class implements IncrementalLoadingBase.
// To create your own Infinite List, you can create a class like this one that doesn't have 'generator' or 'maxcount',
// and instead downloads items from a live data source in LoadMoreItemsOverrideAsync.
public class PCDataIncrementClass<T>: IncrementalLoadingBase
{
/// <summary>
///
/// </summary>
/// <param name="maxPage">共多少页</param>
/// <param name="generator">获取列表的业务函数的委托</param>
/// <param name="strKey">搜索关键字</param>
public PCDataIncrementClass(uint maxPage, GetMoreItemFun generator, string strKey)
{
_generator = generator;
//_maxCount = maxCount;
_strKey = strKey;
_maxPage = maxPage;
}
protected async override Task<IList<object>> LoadMoreItemsOverrideAsync(System.Threading.CancellationToken c, uint count)
{
// Wait for work
await Task.Delay(10);
List<object> list = null;
if (_currentPage <= _maxPage)
{
list = await this._generator(_strKey, _currentPage);
_currentPage++;
}
else
{
return null;
}
//_count += (uint)list.Count;
return list;
}
protected override bool HasMoreItemsOverride()
{
bool isHave = false;
if (_currentPage <= _maxPage) isHave = true;
return isHave;
}
#region State
GetMoreItemFun _generator;
//uint _count = 0;
//uint _maxCount;
string _strKey;
public string SearchKey
{
get { return _strKey; }
set { _strKey = value; }
}
uint _maxPage;
uint _currentPage = 1;
#endregion
}
}
- 已编辑 alvinli87 2012年8月30日 7:42
答案
-
我也遇到了这个问题,后来研究了,发现是GridView有记忆之前的增量集合的状态。目前似乎没有很好的解决办法。我的解决方案是整个将GridView 重新生成。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已标记为答案 Jie BaoModerator 2012年9月10日 6:59
全部回复
-
但从这些代码看不出来,因为从代码看,逻辑是对的,不过你去测试检查下, GridView 和 CollectionViewSource是怎么绑定的,是否有绑定到你的 Items Key上?且你直接设置 CVS的source 为 _productPageGroup。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
-
我也遇到了这个问题,后来研究了,发现是GridView有记忆之前的增量集合的状态。目前似乎没有很好的解决办法。我的解决方案是整个将GridView 重新生成。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已标记为答案 Jie BaoModerator 2012年9月10日 6:59
-
很遗憾,我自己在实现的时候,这个问题在RTM依旧存在,更新了数据源,只要滚动条之前不是在触发增量位置,就不会请求更新新的数据源。
Bob Bao [MSFT]
MSDN Community Support | Feedback to us