c# - ListBox DragDrop auto Scroll issue? -


I have successfully implemented the drag-drop in a list box:

BA Stolnitjh - How do I pull Drop item between data bound items control:

However, when there is a scrollbar in the list and I am at the end of the list, the list box will not scroll automatically until I have an item dragging on.
How do I incorporate that behavior?

EDIT: When I am above the bottom of the list, I want to scroll it, so can I drop anywhere on a small object?

Post text "itemprop =" text ">

I find it using an attached property that adds the ability to scroll control because the mouse moves up or down while dragging The attached asset class is here: -

  Public category DragDropAttProps {Dependency for public static reading property scroll-on dragonproopproperty = dependency form. ("ScrollOnDragDrop", Type, DragDropAttProps, New Property Metadata) (Public, Wrong, HandleScrollOnDragDropChanged); Public Stable Bull GetScrollOnDragDrop (Dependent Object Element) {Return (Boole) Element.Gate Value (ScrollOnDragDropProperty);} Public static void SetScrollOnDragDrop (dependency object element, bool value) {element.SetValue (ScrollOnDragDropProperty, value);} private static void Hendlscolon Dragdropr Chenjed (dependency object D, Dispennseepeprrti-change Aventarj e) {var container = D As Framework Element; if (D null ==) {Debug.Fail ( "Invalid type!");} Unsubscribe (container); If (true.qual (E. NewValue)) {subscribe (container); }} Subscribe to Private Static Zero (Framework Element Container) {container.previewDragOver + = onContainerPreviewDragOver; } Private unsubscribe unsubscribe (Framework Element Container) {container.previewDragOver - = OnContainerPreviewDragOver; } Private static zero oncountain preview preview draggers (object sender, dragent ergues e) {cunt double tolerance = 60; Constant double offset = 20; Var Container = Sender as Framework Element; If (container == empty) {return; } Var Scroll Weaver = Getherstvual Child & lt; ScrollViewer & gt; (Container); If (scrollViewer == zero) {return; } Var verticalPos = e.GetPosition (container) .Y; If (Vertical POS & lt; Tolerance) // // Top of the View List? scroll up. ScrollViewer.ScrollToVerticalOffset (scrollViewer.VerticalOffset - Offset); } And if (vertical POS> container. Realheat - tolerance) {// below the visual list? Scroll down. ScrollViewer.ScrollToVerticalOffset (scrollViewer.VerticalOffset + Offset); }} Private Static T GetFirstVisualChild & lt; T & gt; (DependencyObject depObj) where T: DependencyObject {if (depObj! = Null) {for (var i = 0; i & lt; visualtreehelter.getChildrenCount (depObj); i ++) {var child = VisualTreeHelper Gate Child (Dioobije, I ); If (child is t) {return (t) children; } Var childItem = GetFirstVisualChild & lt; T & gt; (children); If (childItem! = Null) {return childItem; }}} Return tap; }}  

Finally, specify the attached property on the XAML of the Disclaimer Disclaimer: I use this approach on this treeview but it will be used on any scroll control such as should work: -

  & lt; UserControl xmlns: attProps = "clr -namespace: MyAssembly.AttachedProperties; Assembly = MyAssembly" & gt; & Lt; Tree View atoprop: Dragrap Atpopops. Scrolledrooprogress = "true" & gt;  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -