UWP中的第一个可见组

UWP中的第一个可见组

本文介绍了ListView UWP中的第一个可见组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个示例应用程序,当我滚动浏览它时,我试图在其中获得列表视图中的第一个可见组.当我向上滚动以在列表视图中查看初始项目时,会出现问题.它更新顶部可见的组,但仅在列表完成滚动后才更新它的正确性.因此,假设如果我进行轻拂滚动(轻击,滚动并从屏幕上移开手指,并以给定的惯性使其滚动),有时,在更新顶部可见组值时会滞后.这是指向我的示例应用程序的链接: https://1drv.ms/u/s!AhChIerZubKRh3C4DhCZ3K7K7jpm6u

I have this sample application where I am trying to get the first visible group in the list view whenever I scroll through it. The problem occurs when I scroll up to view the initial items in the list view. It updates the top visible group but it only updates it correct when the list is done scrolling. So suppose if I do flick scrolling (tap,scroll and remove the finger from screen and let it scroll with the inertia given), sometimes, it will be lagging while updating the top visible group value. Here's the link to my sample app: https://1drv.ms/u/s!AhChIerZubKRh3C4DhCZ3K7jpm6u

我已上传视频以显示问题所在.在这里,您可以看到仅在滚动完全停止后才会更新顶部的文本块: https://1drv. ms/v/s!AhChIerZubKRh3pmL6IsQNi0Mrm1

I have uploaded the video to show what the issue is. Here you can see that the top text block will only get updated once the scrolling stops completely: https://1drv.ms/v/s!AhChIerZubKRh3pmL6IsQNi0Mrm1

推荐答案

问题在于滚动过程中,名为"tbHeader"的TextBlock的位置是其在ListView中的实际位置,更像是有一个伪造一个用于显示页眉的标题(我将在显示位置显示一个标题TextBlock),并且在滚动停止时,就像将标题TextBlock从其读取位置插入到标题的显示位置一样.

The problem is during scrolling, the TextBlock named "tbHeader"'s position is its real position in the ListView, it's more like there is a fake one for showing the header(I will say a header TextBlock in the showing position), and when scrolling stopped, it's like the header TextBlock is inserted into the header's showing position from its read position.

这是我的解决方案,我们不再找到所有名为"tbHeader"的TextBlock,我们可以在此ListView中找到所有ListViewItemPresenter并找到第一个显示项目,最后显示其"DateTimePropertyOfClassA"(标题)属性.

So here is my solution, we don't find all TextBlocks named "tbHeader" any more, we can find all ListViewItemPresenter in this ListView and find the first showing item, at last show its "DateTimePropertyOfClassA"(header) property.

sv.ViewChanged += (ss, ee) =>
{
    //IEnumerable<TextBlock> tblocks = FindVisualChildren<TextBlock>(lv).Where(x => x.Name == "tbHeader");
    //if (tblocks != null)
    //{
    //    foreach (TextBlock tblock in tblocks)
    //    {
    //        if (IsVisibileToUser(tblock, sv))
    //        {
    //            first.Text = tblock.Text;
    //            break;
    //        }
    //    }
    //}
    IEnumerable<ListViewItemPresenter> presenters = FindVisualChildren<ListViewItemPresenter>(lv);
    if (presenters != null)
    {
        foreach (ListViewItemPresenter presenter in presenters)
        {
            if (IsVisibileToUser(presenter, sv))
            {
                var content = presenter.Content as ClassA;
                first.Text = content.DateTimePropertyOfClassA.ToString();
                break;
            }
        }
    }
};

其他代码保留为我们讨论的最后一种情况.

The other code remain as the last case we discussed.

这篇关于ListView UWP中的第一个可见组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 08:53