WPF Drag-to-scroll doesn't work correctly.

Posted by Garegin on Stack Overflow See other posts from Stack Overflow or by Garegin
Published on 2009-06-02T11:25:46Z Indexed on 2010/05/16 22:40 UTC
Read the original article Hit count: 193

Filed under:
|
|

Hi all, 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

© Stack Overflow or respective owner

Related posts about wpf

Related posts about drag-and-drop