I am tying to realize a drag-to-scroll functionality in my application and have problems on my way. Can anybody help me? I have a ScrollViewer and inside it an ItemsControl and within ItemsTemplate I have a UserControl. I want to drag that UserControl within ItemsControl. I want the ScrollViewer to scroll down, when I am dragging to the boundaries of the ItemsControl.
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);
}
When I start dragging by calling DragDrop.DoDragDrop()
scrolling don't happens. But when I disable dragging, the ScrollViewer scrolls down dependong on mouse position.
Maybe there's something that I don't take into accont about dragging and Capturing the mouse?
Thanks for attention.
Garegin