WPF Drag & drop from ListBox with SelectionMode Multiple

前端 未结 4 1298
后悔当初
后悔当初 2020-12-29 22:47

I\'ve almost got this working apart from one little annoying thing...

Because the ListBox selection happens on mouse down, if you start the drag with the mouse down

4条回答
  •  孤独总比滥情好
    2020-12-29 22:58

    I'm surprised that the behaviour difference between ListBox and the Windows Explorer has not been taken care of after 4 years across 3 major updates of the .NET framework.

    I ran in to this problem back in Silverlight 3. I ended up overriding the mouse down and mouse up event handler to fully simulate the Windows Explorer behaviour.

    I don't have the source code any more but the logic should be:

    When mouse down

    • if the target item is not selected, clear existing selection
      • if Ctrl key is down, add target item to selection
      • if Shift key is down
        • if there is a previously selected item, add all items between target item and previous item to selection
        • else only add target item to selection
    • if the target item is selected de-select only if Ctrl key is down

    When mouse up (on the same item)

    • if the target item is selected
      • if Ctrl key is down, remove item from selection
      • if Shift key is down
        • if there is a previously selected item, remove all items between target item and previous item from selection
        • else only remove target item from selection

    However This should really be Microsoft's job to update the behaviour to be consistent to the operating system and to be more intuitive. I've submitted it as a bug to Microsoft if any body wants to vote for it: http://connect.microsoft.com/VisualStudio/feedback/details/809192/

提交回复
热议问题