DragDrop inside scrollviewer

Aug 6, 2011 at 3:16 PM

Looks like it's not built in. I wrote some code to auto scroll:

https://github.com/michaellperry/MyCon/blob/master/Silverlight4/FacetedWorlds.MyCon/Views/ScheduleView.xaml.cs

Set up a DispatcherTimer for quarter second ticks. Start it on DragStarted, and stop it on DragFinished. Get the mouse position on DragMoved. Use the mouse position in the timer tick to determine whether to scroll.

        void Timer_Tick(object sender, EventArgs e)
        {
            if (_position.X < ScrollEdge)
                Scroller.ScrollToHorizontalOffset(Scroller.HorizontalOffset - ScrollBy);
            else if (_position.X > Scroller.ViewportWidth - ScrollEdge)
                Scroller.ScrollToHorizontalOffset(Scroller.HorizontalOffset + ScrollBy);
            if (_position.Y < ScrollEdge)
                Scroller.ScrollToVerticalOffset(Scroller.VerticalOffset - ScrollBy);
            else if (_position.Y > Scroller.ViewportHeight - ScrollEdge)
                Scroller.ScrollToVerticalOffset(Scroller.VerticalOffset + ScrollBy);
        }

        private void DragSource_DragStarted(object sender, SL_Drag_Drop_BaseClasses.DragEventArgs args)
        {
            _timer.Start();
            _position = args.MouseEventArgs.GetPosition(Scroller);
        }

        private void DragSource_DragFinished(object sender, SL_Drag_Drop_BaseClasses.DragEventArgs args)
        {
            _timer.Stop();
        }

        private void DragSource_DragMoved(object sender, SL_Drag_Drop_BaseClasses.DragEventArgs args)
        {
            _position = args.MouseEventArgs.GetPosition(Scroller);
        }