Click here to Skip to main content
15,946,012 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a ListView with DragDrop enabled and some MouseHandlers and a GridView inside:
XML
<ListView AllowDrop="True" 
          DragEnter="OnDragEnter" 
          Drop="OnDrop"
          ItemsSource="{Binding ...}" 
          SelectedItem="{Binding ...}" 
          PreviewMouseRightButtonDown="OnPreviewMouseRightButtonDown" 
          PreviewMouseRightButtonUp="OnPreviewMouseRightButtonUp" 
          PreviewMouseLeftButtonUp="OnPreviewMouseLeftButtonUp"
          PreviewMouseLeftButtonDown="OnPreviewMouseLeftButtonDown"
          MouseMove="OnMouseMove">
<ListView.View>
    <GridView>
...
    </GridView>
</ListView>

The ScrollBar of the ListView is visible.
When no item is selected in the listview, everthing works fine.
When an item is selected, i notice this behavior:
I click the scrollbar, when the mouse cursor stays inside the bar, everthing is ok, but when it leaves the bar while the mouse button is still pressed,
the scrollbar loses focus and the drag/drop operation which is implemented in MouseMove Handler is executed.

I do not know why the scrollbar loses focus, has anyone an idea?
Posted

1 solution

You have answered your own question ; you are outside of the scrollbar hover over the listview enables the drag and drop. You will need to handle this behavior in your code . You basically will need to ensure that once the mouse is pressed on the scroll bar , it is the control with focus even on a mouse move,
You may get around the behavior by removing your drag and drop event momentarily DragDropEvents -= (DragDropHandler); then renable them after the scroll bar has been let go.

OnMouseMove event is something like my MouseScrollBarSelected - don't drag and drop, (remove the handler) MouseScrollBarUnSelected reenable my DragDropEvent,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900