Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WP 8.1 ISupportIncrementalLoading LoadMoreItemsAsync不断被调用_C#_Xaml_Windows Phone 8_Infinite Scroll - Fatal编程技术网

C# WP 8.1 ISupportIncrementalLoading LoadMoreItemsAsync不断被调用

C# WP 8.1 ISupportIncrementalLoading LoadMoreItemsAsync不断被调用,c#,xaml,windows-phone-8,infinite-scroll,C#,Xaml,Windows Phone 8,Infinite Scroll,我试图使用以下示例实现无限滚动 问题是,在我的例子中,LoadMoreItemsAsync不断被调用。我正在一个集线器上开发它(不确定这是否有区别)并使用MVVMLight。下面是我的代码 .xaml 下面是我对iSupportIncrementLoading的实现 公共类IncrementalLoadingNotificationsCollection:ObservableCollection,ISupportIncrementalLoading { 私人信息服务(notificati

我试图使用以下示例实现无限滚动

问题是,在我的例子中,LoadMoreItemsAsync不断被调用。我正在一个集线器上开发它(不确定这是否有区别)并使用MVVMLight。下面是我的代码

.xaml


下面是我对iSupportIncrementLoading的实现

公共类IncrementalLoadingNotificationsCollection:ObservableCollection,ISupportIncrementalLoading
{
私人信息服务(notificationService);;
公共增量AlloadingNotificationsCollection(INotificationService notificationService)
{
HasMoreItems=true;
_notificationService=notificationService;
}
公共物品
{
得到;
私人设置;
}
公共IAsyncOperation LoadMoreItemsAsync(uint计数)
{
返回InnerLoadMoreItemsAsync(count).asAsAsAsyncOperation();
}
专用异步任务InnerLoadMoreItemsAsync(uint expectedCount)
{
var actualCount=0;
IList通知;
尝试
{
notifications=wait_notificationService.GetNotificationsAsync(ConfigurationSettings.AccessToken,8);
}
捕获(例外)
{
HasMoreItems=false;
投掷;
}
if(notifications!=null&¬ifications.Any())
{
foreach(通知中的var通知)
{
添加(通知);
}
actualCount+=通知。计数;
//_photoStartIndex+=(uint)实际计数;
}
其他的
{
HasMoreItems=false;
}
返回新的LoadMoreItemsResult
{
计数=(uint)实际计数
};
}
}
下面给出的是viewmodel的摘录

public incrementAlloadingnotifications集合增量通知
{
得到
{
返回增量通知;
}
设置
{
_增量通知=值;
如果(!Equals(null)&&&_incrementalNotifications.Count>0)
{
DispatcherHelper.CheckBeginInvokeOnUI(()=>
{
RaisePropertyChanged(()=>增量通知);
});
}
}
}

非常感谢您对解决此问题的任何帮助。

玩过之后,我设法解决了此问题。问题是ListView所在的StackPanel。我不知道为什么,但由于某种原因,StackPanel的存在导致LoadMoreItemsAsync被无休止地调用,我一删除它,它就工作得很好。

正如您在回答中提到的,StackPanel就是罪魁祸首。StackPanel控件不会约束其内容的大小。这意味着随着ListView加载更多的项目,ListView在StackPanel中的高度也会增加,因此ListView认为每个项目都是可见的,因此加载更多的项目,依此类推

这也会影响虚拟化,这也是您不应该将ListView放入StackPanel的另一个原因。根据报告:

如果ItemsControl视口的大小不受限制,则该控件不执行虚拟化。相反,它为集合中的每个项目创建一个项目容器。一些不限制视口大小的常见容器是Canvas、StackPanel和ScrollViewer。在这种情况下,可以通过直接设置ItemsControl的大小来启用虚拟化,而不是通过其父容器来设置其大小

因此,您的选择是:

  • 不要使用StackPanel容器。改用网格
  • 如果要使用StackPanel容器,则必须手动设置ListView的大小(高度)

你是个救命的人。引用文档的摘录救了我。在我的例子中,是堆栈面板和滚动查看器导致了问题,而我一直在尝试修复listview|