Drag and drop from list to canvas on windows phone with MVVM

那年仲夏 提交于 2019-11-29 14:35:49

There exists no samples or anything to accomplish this. I have contacted people at msdn, and Microsoft, without any success. I am trying to build a sample but so far no success.

Edit

So what I did to solve this issue: first the problem graphically

In words dragging an element from listbox to a Canvas. SO what I did I added handlers to the listbox like this, in the view:

        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);

Furthermore I add an extra canvas, here after referred to as Canvas2, that stretches behind the ListBox and Canvas. The only difference between the two canvas' are the size, else they have the same itemscontrol but with different observablecollections binded to the canvas'.

  1. In ManipulationStarted I find the element and add a new one to the observablecollection of Canvas2. Furthermore I Set the zindex of Canvas2 to be infront.
  2. I then tap into the delta event to move the element around on Canvas2
  3. in ManipulationCompleted I check if the element is inside the bounds of the first Canvas.
  4. I then delete it from Canvas2, and move Canvas2 to the back, using Canvas.SetIndex(UIElement, zIndex)
  5. Depending on the bounds check in (3.) I then add it to the first canvas. And everything works.

But I do not use the drop feature or the related events since it did not seem to help because of the missing dragable element. But this works :)

Silverlight on WP7 does not support drag and drop – at least not fully. It supports drag but not drop.

Anyways you can try something with the following example,

WP7 Drag & Drop Example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!