合并滚动-“逐像素” + “逐项”
我有一个拖放框架,其中已经存在滚动支持(逐像素滚动)。在未启用虚拟化的情况下,这很有效,但如果启用了虚拟化,那么它就会变得混乱。
由于滚动的逻辑基于视口高度,并且根据 MSDN,我们 -
MSDN - 如果 CanContentScroll 为 true,则 ExtentHeight、ScrollableHeight、ViewportHeight 和 VerticalOffset 属性的值是项目数。如果 CanContentScroll 为 false,则这些属性的值为设备独立像素。另外,如果启用虚拟化,则 ExtentHeight 表示 - ScrollViewer 中的项目总数,视口高度表示当前可见的项目数。
因此,滚动功能工作我想要类似的东西 -
ScrollToContent(ScrollViewer, CurrentMousePositionWRTScrollViewer)
{
if(ScrollViewer's Viewport Height is in terms of Pixel)
{
----------Do Pixel by Pixel Scrolling --------
}
else if(ScrollViewer's Viewport Height represents number of items visible)
{
--------- Do Item by Item Scrolling ---------
}
我尝试检查“CanContentScroll = false”,检查虚拟化是否启用,但即使该功能也有效,因为我发现即使 CanContentScroll 为 true,视口高度功能也代表了项目可见,但等于实际高度。然而,在另一个列表框中,它显示 - 可见项目的数量。
滚动的实际代码 -
private void ScrollToContent(ScrollViewer scrollViewer, Point point)
{
double verticalScrollOffset = 0.0;
double scrollDifference = 30.0;
double scrollDefaultOffset = 40.0;
if (scrollViewer == null) return;
if (scrollViewer.ViewportHeight != scrollViewer.ExtentHeight)
{
if (scrollViewer.ViewportHeight - point.Y < scrollDifference)
{
// See if we need to scroll down
verticalScrollOffset = scrollDefaultOffset;
}
else if (point.Y < scrollDifference)
{
// See if we need to scroll up
verticalScrollOffset = -scrollDefaultOffset;
}
// Scroll up or down
if (verticalScrollOffset != 0.0)
{
verticalScrollOffset += scrollViewer.VerticalOffset;
if (verticalScrollOffset < 0.0)
{
verticalScrollOffset = 0.0;
}
else if (verticalScrollOffset > scrollViewer.ScrollableHeight)
{
verticalScrollOffset = scrollViewer.ScrollableHeight;
}
scrollViewer.ScrollToVerticalOffset(verticalScrollOffset);
}
}
}
我幻想虚拟化是罪魁祸首,但在检查 IsVirtualization 属性后,我注意到虚拟化在这里不是问题(这对于两个列表框都是如此)..任何想法可能是什么情况??
问题是 - 我有 2 个列表框(几乎相似) 在一种情况下我得到 视口高度 == 可见项目数 然而在其他情况下 视口高度 = 实际高度 ..
可能的原因是什么?
I've a Drag-Drop framework in which scrolling support is already there (Pixel by Pixel scrolling). This works good in case Virtualization is not enabled but if it is enabled then it gets messed up.
As the logic of scrolling is based on Viewport height and as per MSDN we've -
MSDN- If CanContentScroll is true, the values of the ExtentHeight, ScrollableHeight, ViewportHeight, and VerticalOffset properties are number of items. If CanContentScroll is false, the values of these properties are Device Independent Pixels. Also If Virtualization is Enabled then ExtentHeight Represents - TotalNumber of Items in ScrollViewer and Viewport Height Represents Count of Items currently visible.
So scrolling dint work i want something like--
ScrollToContent(ScrollViewer, CurrentMousePositionWRTScrollViewer)
{
if(ScrollViewer's Viewport Height is in terms of Pixel)
{
----------Do Pixel by Pixel Scrolling --------
}
else if(ScrollViewer's Viewport Height represents number of items visible)
{
--------- Do Item by Item Scrolling ---------
}
I tried putting check of "CanContentScroll = false", checking Virtualization is enabled or not but even that dint work because i found that in one even if CanContentScroll is true Viewport height dint represent the number of items visible but it's equal to actual height. However on another listbox it shows - the number of items visible.
Actual Code of scrolling -
private void ScrollToContent(ScrollViewer scrollViewer, Point point)
{
double verticalScrollOffset = 0.0;
double scrollDifference = 30.0;
double scrollDefaultOffset = 40.0;
if (scrollViewer == null) return;
if (scrollViewer.ViewportHeight != scrollViewer.ExtentHeight)
{
if (scrollViewer.ViewportHeight - point.Y < scrollDifference)
{
// See if we need to scroll down
verticalScrollOffset = scrollDefaultOffset;
}
else if (point.Y < scrollDifference)
{
// See if we need to scroll up
verticalScrollOffset = -scrollDefaultOffset;
}
// Scroll up or down
if (verticalScrollOffset != 0.0)
{
verticalScrollOffset += scrollViewer.VerticalOffset;
if (verticalScrollOffset < 0.0)
{
verticalScrollOffset = 0.0;
}
else if (verticalScrollOffset > scrollViewer.ScrollableHeight)
{
verticalScrollOffset = scrollViewer.ScrollableHeight;
}
scrollViewer.ScrollToVerticalOffset(verticalScrollOffset);
}
}
}
I was in illusion that virtualization is culprit but after checking IsVirtualization property, I noticed that virtualization is not an issue here (its true for both listboxes) .. Any Idea what can be the possible case ??
Issue is - I've 2 listboxes (almost similar) In one case i get
ViewPort Height == Number of Items visible
However in other case
ViewPort Height = Actual Height ..
What can be the possible reason ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
回答实际高度与视口高度和滚动问题
代码:我使用选定的项目在启用虚拟化的情况下执行逐项滚动
Answer Actual Height Vs Viewport Height and Scrolling Issue
Code : I used selected Item to perfrom Item by Item scrolling in case of Virtualization enabled