如何防止CollectionView在.NET MAUI中将滚动位置重置为开头。

huangapple go评论77阅读模式
英文:

How to keep CollectionView from resetting its scroll position to beginning .NET MAUI

问题

当重新分配CollectionView时,它会将滚动位置重置到开头。例如,我有一个搜索功能,当输入时,会将当前的CollectionView itemsSource 过滤到一个新列表,然后将其分配为新的itemsSource,它可以正常工作,但当我重新分配原始itemsSource 时,CollectionView的滚动位置会重置到开头。我猜这是有道理的,但我该如何防止它发生呢?

我尝试查看其属性,也许可以找到一些东西,可以提供给我当前滚动到的位置,这样我就可以在它重置后使用其ScrollTo函数手动滚动到该位置,但我没有找到任何东西。

有什么方法吗?如何找到CollectionView的当前滚动位置?

英文:

When CollectionView is reassigned it resets its scroll position back to beginning.
for example i have a search function that when typed in filters the current CollectionView itemsSource to a new list and then assigns this as the new itemsSource it works but when i reassign the original itemsSource The CollectionView's scroll position resets to beginning. i guess it makes sense but how do i keep it from doing that?

I've tried looking through its properties to perhaps find something that would give me the current position its scrolled to so i can manually scroll to that position after it resets using its ScrollTo function but i didn't find anything.

is there anyway? how can i find the current scroll position of CollectionView?

答案1

得分: 0

这不是回答你的问题,但请听我说。

你可以使用两种不同的控件。

一个是永久的,一个是可变的,分配了命令(例如轻触手势)指向相同的代码,并显示适当的内容。

我没有在 CollectionView 中精确使用过它,但在非常相似的情况下使用过。

除了性能问题之外,这是一个强大的选择。最重要的是,对于容器来说是有效的。考虑到子元素现在不会继承父元素的状态...

英文:

It is not answer to your question, but hear me out.

You can use two different controls.

One permanent, and one changing, with assigned commands (for example tap gesture) pointing to the same code, and display the appropriate one.

I have not used it for CollectionView precisely, but for very similar situation.

Performance issues aside, this is a powerful option. And most importantly - a working one for containers. Considering that the childs do not take the state of the parent right now...

huangapple
  • 本文由 发表于 2023年3月7日 15:56:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75659270.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定