Drag and drop from list to canvas on a Windows phone using MVVM

I have an application in which the user can manipulate elements selected from the list, this is done by clicking on the list item and the item is added to the canvas.

During user testing of the application. People have found that this is not intuitive, since they want to drag. I found some links describing how to implement this for WPF, i.e. not for Windows Phone.

While trying to replicate code from the msdn project , I ran into problems that could not get the same item information from DragEventArgs.

So, what I want to do, the user can drag the item into the list onto the canvas. I tried in Viewmodel but there was no information in DragEventArgs like e.Data and e.Source. I also tried in the xaml.cs file without success.

Any help is appreciated.

Idea

  • make a copy of your item when you select it,
  • add a copy as a child of your canvas,
  • set the x, y copy coordinates according to the selected location of the element,
  • CaptureMouse () in copy.

Of course, Windows Phone Manipulation uses a delta to move it instead of grabbing the mouse. I can move an element inside a Canvas after it has been added by the Click event. But I can not drag from the list to work. The points above are the method that I have, and we try, but without success.

+4
2

- . msdn Microsoft - . , .

Edit

, : enter image description here

. , , , , :

        MyLB.AddHandler(UIElement.ManipulationStartedEvent, new EventHandler<ManipulationStartedEventArgs>(MyLB_ManiStarted), true);
        MyLB.AddHandler(UIElement.ManipulationDeltaEvent, new EventHandler<ManipulationDeltaEventArgs>(MyLB_ManiDelta), true);
        MyLB.AddHandler(UIElement.ManipulationCompletedEvent, new EventHandler<ManipulationCompletedEventArgs>(MyLB_ManiCompleted), true);

, extra, Canvas2, ListBox Canvas. - , , , ".

  • ManipulationStarted Canvas2. , zindex of Canvas2 .
  • delta, Canvas2
  • ManipulationCompleted , .
  • Canvas2 Canvas2 , Canvas.SetIndex(UIElement, zIndex)
  • (3.) . .

drop , , , - . :)

+1

Silverlight WP7 - , . , .

- ,

WP7 Drag and Drop

0

Source: https://habr.com/ru/post/1535002/


All Articles