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

后端 未结 2 504
你的背包
你的背包 2020-12-21 02:47

I have an app where a user can manipulate around with elements chosen from a list, this is done by clicking the list element and the element is added to a canvas.

Du

相关标签:
2条回答
  • 2020-12-21 03:24

    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

    0 讨论(0)
  • 2020-12-21 03:25

    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 enter image description here

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

    0 讨论(0)
提交回复
热议问题