我想在我的应用程序中实现拖动滚动功能,但在路上遇到了问题。有谁能够帮我?我有一个 ScrollViewer,其中有一个 ItemsControl,在 ItemsTemplate 中有一个 UserControl。我想在 ItemsControl 中拖动那个 UserControl。当我拖动到 ItemsControl 的边界时,我希望 ScrollViewer 向下滚动。
protected override void OnPreviewMouseMove(System.Windows.Input.MouseEventArgs e)
{
if (this.IsMouseCaptured)
{
// Get the new mouse position.
Point mouseDragCurrentPoint = e.GetPosition(this);
if (Math.Abs(mouseDragCurrentPoint.Y - this.ActualHeight) <= 50)
{
this._scrollStartOffset.Y += 5;
_containingScrollViewer.ScrollToVerticalOffset(this._scrollStartOffset.Y);
}
if (mouseDragCurrentPoint.Y <= 50)
{
this._scrollStartOffset.Y -= 5;
_containingScrollViewer.ScrollToVerticalOffset(this._scrollStartOffset.Y);
}
}
base.OnPreviewMouseMove(e);
}
当我通过调用DragDrop.DoDragDrop()
滚动开始拖动时不会发生。但是当我禁用拖动时,ScrollViewer 会根据鼠标位置向下滚动。也许有一些我不考虑拖动和捕获鼠标的事情?感谢关注。加雷金