'WPF implement VirtualizingPanel IScrollInfo, not trigger MeasureOverride/ArrangeOverride/SetVerticalOffset/SetHorizontalOffset when scrolling
I am implementing my own VirtualizingPanel with IScrollInfo interface, and scroll behavior is weird
normal behavior I want to like StackPanel, panel move with dragging the scroll bar
I realize MeasureOverride/ArrangeOverride will be triggered all the time when dragging scroll bar, but my pannel only triggers once after mouse release.
My code file is long, and I paste a part of the code that I think is important.
public class MyVirtualizingPanel : VirtualizingPanel, IScrollInfo
{
public void LineLeft()
{
SetHorizontalOffset(HorizontalOffset - ScrollHorizonLineSize);
}
public void LineRight()
{
SetHorizontalOffset(HorizontalOffset + ScrollHorizonLineSize);
}
public void SetHorizontalOffset(double offset)
{
if (offset < 0 || ViewportWidth >= ExtentWidth)
{
offset = 0;
}
else if (offset + ViewportWidth >= ExtentWidth)
{
offset = ExtentWidth - ViewportWidth;
}
Offset = new Point(offset, Offset.Y);
ScrollOwner?.InvalidateScrollInfo();
InvalidateMeasure();
}
protected override Size MeasureOverride(Size availableSize)
{
// update scoll size
if (ViewPort != availableSize)
{
ViewPort = availableSize;
this.ScrollOwner.InvalidateScrollInfo();
}
var extent = CalcExtent(availableSize);
if (extent != Extent)
{
Extent = extent;
this.ScrollOwner.InvalidateScrollInfo();
}
// virtualizing
// ...
return Extent;
}
protected override Size ArrangeOverride(Size finalSize)
{
for (int index = 0; index < InternalChildren.Count; index++)
{
child.Arrange(CalcChildRect(index));
}
return finalSize;
}
}
What should I do?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
