本文介绍了拖放从列表中画布上的窗户手机MVVM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个应用程序,其中用户可以操纵围绕从列表中选择的元素,这是通过点击列表元素和该元素被添加到画布完成 在应用程序的用户测试。人们发现其不属于,因为他们想要拖放直观。我发现几个链接描述了如何实现此为WPF,即不适用于Windows手机。 试图从的 MSDN项目我结束了,我不能获取有关DragEventArgs元素相同的信息的问题。 所以,我要完成的是用户可以在一个列表框拖拽一个元素到画布上。我曾尝试在视图模型,但缺少DragEventArgs信息,如e.Data和e.Source。我也试图在xaml.cs没有成功文件。 任何帮助表示赞赏。 创意 创建你的元素的副本时,它的选择, 添加副本作为画布的孩子, 设置副本的x,y坐标,以在符合所选元素的位置, CaptureMouse()该副本。 当然,在Windows Phone操纵三角洲应该用来代替移动它捕获鼠标。我可以拖动的元素Canvas中它是由一个Click事件后添加。但我似乎无法得到从列表中拖动到工作。上面的要点是一个方法我已经和正在尝试,但没有至今没有成功。 解决方案 有不存在的样品或任何东西做到这一点。我所接触的MSDN和微软的人,没有任何成功。我想建立一个样本,但至今没有成功。 修改 所以我做了什么来解决这个问题:第一个问题图形 在拖动的话,从列表框中一个元素到画布上。所以我做了我加处理像这样的列表框,在视图中: MyLB.AddHandler(UIElement.ManipulationStartedEvent,新事件处理< ManipulationStartedEventArgs>(MyLB_ManiStarted),TRUE); MyLB.AddHandler(UIElement.ManipulationDeltaEvent,新的EventHandler< ManipulationDeltaEventArgs>(MyLB_ManiDelta),TRUE); MyLB.AddHandler(UIElement.ManipulationCompletedEvent,新的EventHandler< ManipulationCompletedEventArgs>(MyLB_ManiCompleted),TRUE); 此外,我添加的额外的画布上,这里被称为Canvas2后,绵延列表框和画布后面。 两个帆布之间唯一的区别是大小,否则它们具有相同的ItemsControl但具有绑定到画布不同observablecollections' 在在ManipulationStarted我发现元素,并添加一个新的以Canvas2的的ObservableCollection。此外,我将Canvas2的zIndex的是盈方。 我再进军增量事件对Canvas2在在ManipulationCompleted四处移动元素 我检查,如果该元素是第一的边界内帆布。 我再从Canvas2删除和移动Canvas2到后面,用 Canvas.SetIndex(的UIElement,zIndex的) 根据不同的边界检查(3)然后,我把它添加到第一个画布。和一切正常。 但我不使用拖放功能或相关的事件,因为它似乎并没有帮助,因为失踪者dragable元素。但这个工程:) 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.During a user testing of the app. People found it not to be intuitive since they wanted drag and drop. I have found several links describing how to implement this for WPF, i.e. not for windows Phone.Trying to replicate the code from a msdn project i ended up with problems that I cannot get the same information about the elements from DragEventArgs.So what I want to accomplish is user can drag an element in a listbox to a canvas. I have tried in the Viewmodel but missing information in DragEventArgs, like e.Data and e.Source. I have also tried in the xaml.cs file with no success.Any help is appreciated.Ideacreate a copy of your element when it's selected,add the copy as a child of your canvas,set the copy's x,y coordinates to match the selected element's location,CaptureMouse() on the copy.Of course on Windows Phone Manipulation delta should be used to move it instead of capture mouse. I am able to drag an element around inside the Canvas after it was added by a Click event. But I can't seem to get drag from list to work. The bullet points above is a method I have and are trying but without any success so far. 解决方案 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.EditSo what I did to solve this issue: first the problem graphicallyIn 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'.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.I then tap into the delta event to move the element around on Canvas2in ManipulationCompleted I check if the element is inside the bounds of the first Canvas.I then delete it from Canvas2, and move Canvas2 to the back, using Canvas.SetIndex(UIElement, zIndex)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 :) 这篇关于拖放从列表中画布上的窗户手机MVVM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-06 05:15