有没有办法确保 Silverlight ScrollViewer 保持顶部项目完全可见

发布于 2024-12-06 16:33:50 字数 301 浏览 0 评论 0原文

在 Silverlight 4 中,有没有一种方法可以让您在 ScrollViewer 中翻页(即单击拇指附近区域的滚动条)时,顶部的任何项目都完全可见。当拖动拇指或使用鼠标滚轮时,我仍然需要它平滑滚动。

我的客户不喜欢当他向下翻页列表时某个项目被切成两半,因为它在顶部和底部时都会被切成两半。我建议某种整体卷轴,但他不喜欢。他希望它仍然能够平滑滚动,除非向上或向下翻页。

编辑

这里有一个要点。这些物品的尺寸不一样。所以我必须检测滚动查看器顶部的项目并将其滚动到视图中。有没有简单的方法可以做到这一点?

In Silverlight 4, is there a way that whenever you page down a ScrollViewer (i.e click the scroll bar in the area adjacent to the thumb) whatever item is at the top is completely visible. I still need it to scroll smoothly when the thumb is dragged or the mouse wheel is used.

My client doesn't like that an item is cut in half when he pages down the list because it is cut in half both when its at the top and when its at the bottom. I suggested some sort of integral scroll, and he didn't like it. He wants it to still scroll smoothly unless paging up or down.

Edits

Here's the catch. The items are not the same size. So I have to detect the item that is at the top of the scroll viewer and Scroll it into view. Is there an easy way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尬尬 2024-12-13 16:33:50

您需要做的第一件事是从 ScrollViewer 的内部挖出垂直滚动条。您可以在 VisualTreeHelper 的帮助下完成此操作。各种博客中有许多小代码块,使其使用更加容易。我推荐这个 VisualTreeEnumeration (但我不会我不是)。使用该扩展类,您可以获得垂直滚动条:

ScrolBar vertSB = someScrollViewer.Descendents()
                                  .OfType<ScrollBar>()
                                  .FirstOrDefault(sb => sb.Name = "VerticalScrollBar");

现在您可以附加到滚动事件并确定发生的滚动类型,如下所示:

vertSB.Scroll += (s, args) =>
{
     if (args.ScrollEventType == ScrollEventType.LargeDecrement
         || args.ScrollEventType == ScrollEventType.LargeIncrement)
     {
          // using args.NewValue determine the correct Integral value and assign
          // using someScrollViewer.ScrollToVerticalOffset
     }
};

The first thing you need to do is dig out the vertical scroll bar from the internals of the ScrollViewer. You can do this with the help of VisualTreeHelper. There are a number of little chunks of code in various blogs the make its use even easier. I recommend this VisualTreeEnumeration (but I would wouldn't I). With that extensions class in place you can get the vertical scroll bar with:

ScrolBar vertSB = someScrollViewer.Descendents()
                                  .OfType<ScrollBar>()
                                  .FirstOrDefault(sb => sb.Name = "VerticalScrollBar");

Now you can attach to is Scroll event and determine the type of scroll that occured like this:

vertSB.Scroll += (s, args) =>
{
     if (args.ScrollEventType == ScrollEventType.LargeDecrement
         || args.ScrollEventType == ScrollEventType.LargeIncrement)
     {
          // using args.NewValue determine the correct Integral value and assign
          // using someScrollViewer.ScrollToVerticalOffset
     }
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文