0

How can I scroll a ScrollViewer while and only while a dragged file or control is over a specific droppable control? C# VisualStudio 2015 Community

Not the same questions as WPF - How could I get a scrollviewer control from my XAML file in C#?, though it does look like we are trying to do the same thing.

I can access my scrollviewer and I can use VerticalOffset to make it scroll. I just can't figure out how to keep it scrolling until the file or control being dragged is no longer over the control. I have tried several while loops, but have not yet found a condition that I could use to break it. Below is one such attempt.

Thank you, Eric

bool continueScroll = false; // global variable

private void Drag_Enter_Scroll_Down(object sender, DragEventArgs e)
{
    continueScroll = true;
    while (continueScroll)
    {
        imageScrollViewer.ScrollToVerticalOffset(imageScrollViewer.VerticalOffset + 0.1);
    }
}

private void Drag_Leave_Scroll_Down(object sender, DragEventArgs e)
{
    continueScroll = false;
}
Community
  • 1
  • 1
Eric
  • 243
  • 1
  • 3
  • 7
  • Turning on & off the scrollviewer in IsOver event of the specific droppable control or utilizing MouseEnter, MouseLeave event might be one of the options..I don't know while loop with Verticaloffest will work how precisely but yourobject.BringIntoView(); is what I'm using with nice performance. – Kay Lee May 30 '16 at 04:20
  • 1
    Maybe it's an infinite loop you created, but you could try to use a Timer instead and then just start and stop it in your events to take care of your scrolling. –  May 30 '16 at 06:20
  • 1
    The basic issue in your example above is that you never return from the event handler, which blocks the dispatcher thread, preventing further events. A timer could work, but you don't really need that. See the marked duplicate, which uses the `DragDrop.PreviewDragOver` event to invoke scrolling behavior. That event is raised continuously (i.e. repeatedly) during drag operations, and so you can simply invoke a single scroll operation each time. Scrolling will happen continuously. Consider refining the behavior by scrolling a larger amount the further the mouse is from the triggering edge. – Peter Duniho May 30 '16 at 06:42
  • @PeterDuniho - Thank you very much. I searched and looked. I have no idea why I didn't find this article. One of my searches was literally "scrolling dragging" – Eric May 30 '16 at 13:45

0 Answers0