WPF ListView Databound Drag/Drop Auto Scroll

后端 未结 3 671
轻奢々
轻奢々 2021-02-06 09:03

I\'ve been working with Bea\'s solution here for a while and finding it very helpful. Problem now I\'m having is when I drag-n-drop items within or to another ListView control

3条回答
  •  一向
    一向 (楼主)
    2021-02-06 09:46

    Another possibility to scroll is to use the ScrollBar-Commands. You can do this without climbing down the VisualTree. If you have a styles ListBox with no border the GetScrollViewer()-Method would not work anymore.

    I use the first Element of the ItemContainerGenerator as CommandTarget for the ScrollBar.LineXXXCommand:

    Point p = e.GetPosition(itemsControl);
      IInputElement commandTarget = itemsControl.ItemContainerGenerator.ContainerFromIndex(0) as IInputElement;
    
      if (commandTarget != null)
      {
        if (p.Y < OFFSET_TO_SCROLL)
          ScrollBar.LineUpCommand.Execute(null, commandTarget);
        else if (p.Y > itemsControl.ActualHeight - OFFSET_TO_SCROLL)
          ScrollBar.LineDownCommand.Execute(null, commandTarget);
    
        if (p.X < OFFSET_TO_SCROLL)
          ScrollBar.LineLeftCommand.Execute(null, commandTarget);
        else if (p.X > itemsControl.ActualWidth - OFFSET_TO_SCROLL)
          ScrollBar.LineRightCommand.Execute(null, commandTarget);
      }
    

    Calling the LineXXXCommands is similiar to clicking the Arrow-Buttons of a ScrollBar: The ScrollViewer scrolles by a certain ammount which you can configure by setting the 'SmallAmount' Property of the ScrollBar.

提交回复
热议问题