Dragging and reordering listbox items in Windows p

2019-07-15 21:53发布

问题:

I have been looking for a drag and drop listbox, but I guess there is no such default control. A bit of searching has given me,Jason's Blog in which he has pulled it off very gracefully.. In the code he has written, there is a the drag and drop handler which is present at the right end of every listboxitem.. You press on the handler and move the item up or down. I am trying to implement the same on the long press of the item..

He uses a drag interceptor which is basically a canvas and it sits on top of listbox to capture the listboxitem manipulation events. If I want the same manipulation on the hold event of the listbox item, how do I trigger it??

This is how I have linked the events to the drag interceptor. How do i call the Manipulation Started on the hold of the listbox item?? Or is there some other way to do this?

this.dragInterceptor.ManipulationStarted += this.dragInterceptor_ManipulationStarted;
this.dragInterceptor.ManipulationDelta += this.dragInterceptor_ManipulationDelta;
this.dragInterceptor.ManipulationCompleted += this.dragInterceptor_ManipulationCompleted;
this.dragInterceptor.Hold += dragInterceptor_Hold;

回答1:

Have you tried only adding the manipulation event handlers once the hold event is triggered? Or adding a flag which is set on Hold and cleared on ManipulationCompleted to test if the hold was done before running the main code in the other manipulation events.



回答2:

I triggered the manipulation events of the reorder listbox by sending the arguments (object sender and ManipulationStartedEventArgs) from the mainpage.xaml.