【问题标题】:Win 8.1 ScrollViewer issues with a GridViewWin 8.1 ScrollViewer 的 GridView 问题
【发布时间】:2013-11-09 15:44:58
【问题描述】:

我有一个 VariableSizeGridView(又名带有 VariableSizedWrapGrid 的 GridView),并且由于框架不支持 VariableSizedWrapGrid 上的 ISupportIncrementalLoading,我通过“侦听”GridView 父 ScrollViewer 来实现自己的框架(这个特定情况下是 Hub 控件)

一切正常,当我到达滚动查看器的末尾时,我的代码调用了一个例程来获取更多数据。

当新数据出现在屏幕上时出现问题,scrollviewer 自动滚动到末尾并重新开始加载过程,如果我不将滚动条移到其他位置,则以无限循环结束。

有什么方法可以防止我添加了一些项目后滚动查看器自动走到最后?

谢谢

【问题讨论】:

    标签: c# xaml windows-8 windows-runtime scrollviewer


    【解决方案1】:

    您可以创建一个覆盖 VariableSizeGridView 的自定义控件,并像您一样监听滚动查看器。由于您可以访问 GridView 的最新元素,因此在开始加载更多元素后,您可以将滚动查看器设置为最新的位置位置。获取对该元素的视觉引用,然后调用此代码:

    FrameworkElement focusedElement = FocusManager.GetFocusedElement() as FrameworkElement;
            GeneralTransform focusedVisualTransform = parent.TransformToVisual(_scrollViewer);
    
    ApplyHorizontalScrolling(focusedElement, focusedVisualTransform);
    
      private void ApplyHorizontalScrolling(FrameworkElement focusedElement, GeneralTransform focusedVisualTransform)
        {
            Rect rectangle = focusedVisualTransform.TransformBounds(new Rect(new Point(focusedElement.Margin.Left, focusedElement.Margin.Top), focusedElement.RenderSize));
            double horizontalOffset = _scrollViewer.HorizontalOffset + (rectangle.Left);
            _scrollViewer.ChangeView(horizontalOffset, 0, _scrollViewer.ZoomFactor);
        }
    

    使用和调整此代码,将帮助您防止滚动条转到最新位置。

    【讨论】:

    • 谢谢,我实际上做了一些不同的事情,我在新项目出现之前存储滚动查看器的最后位置,在滚动查看器大小更改后,我将水平滚动设置为以前的值; ) 无论如何谢谢!
    猜你喜欢
    • 2015-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多