I am trying to implement a drag and drop mechanism in a wp8.1 app. I was trying the ManipulationDelta event for that but, then stumbled upon the DragEnter and Drop event. I tried it with the following xaml code but the DragEnter event handler isn't being invoked. What is the correct way to do this? I couldn't find much information about it on the net.
<Rectangle Height="50" Width="50" Fill="#FF5D1111"
x:Name="rectangle"
AllowDrop="True"
DragEnter="rectangle_DragEnter"></Rectangle>
There's a bit more involved in hooking up drag and drop. The DragEnter event will not fire simply because another element is dragged over it using a transform.
A drag (and drop) operation is initiated by calling DragDrop.DoDragDrop(...), typically within a MouseMove event.
Drag and Drop takes a few steps to setup, and can seem quite daunting for something that should be so simple. There are some good tutorials out there. This post explains the process with the minimum fuss :)
UPDATE: This solution is for WPF/Desktop apps. Windows Phone doesn't implement DragDrop in this way.
Related
I am developing UWP application. In one scenario, I am having multiple ListView on a canvas and I want to perform Drag and Drop between ListViews. While performing Drag-Drop scroller doesn't moves.
I tried to implement Behaviour defined in this Link. But it is not working as PreviewDragOver event is not available in UWP.
Is there any way to implement it ?
While PreviewDragOver is not available in UWP, the DragOver event definitely is. It seems it should be possible to use this event in the attached behavior instead.
I want my WPF application to indicate that a drag and drop operation should be cancelled in certain situations. The operation is being started from an external application (e.g. Windows Explorer).
I've tried hooking up the following events to see when they fire;
<someControl
AllowDrop="True"
DragOver="OnDragOver"
PreviewQueryContinueDrag="OnPreviewQueryContinueDrag"
QueryContinueDrag="OnQueryContinueDrag" />
The idea being that I would let the other application know that it should end the operation by specifying DragAction.Cancel on the event args.
However, neither PreviewQueryContinueDrag nor QueryContinueDrag ever fire. I hooked up DragOver just to make sure anything was firing at all, and it works as expected.
Am I missing something, or is it the case that the drag source application just doesn't do anything with this event?
According to the MSDN documentation (http://msdn.microsoft.com/en-us/library/system.windows.uielement.querycontinuedrag.aspx), the QueryContinueDrag event is for the drag source, not for the drop target. In your case, the drag source is the external application, the drop target is the WPF control. Therefore, you can use this event only for drag&drop operations initiated by a WPF application.
I have a somewhat unusual design problem in a WPF touch application.
I have a UserControl that holds an image, which I allow the user to freely move, resize, and rotate around the touch surface using multitouch by setting:
isManipulationEnabled = true
and then hooking up events for ManipulationStarting, ManipulationDelta, and ManipulationCompleted.
This is all good and works perfectly, but now I would like to add the ability for a user to drag this control into the WrapPanel on another control, which has a list of image files, and add this image to the list.
I tried using DragDrop events by calling DragDrop.DoDragDrop() on the ManipulationDelta event, but it locks the UI and the control until a drop occurs, which is not what I want.
Is there any way to properly do this without writing my own hit-testing code? I'm using WPF 4.0 and .NET 4.5 on VS 2013, and I'm not sure if the Surface SDK would help me in this case (nor could I properly install/load it to VS2013)
Found my solution: Use VisualTreeHelper.HitTest and call the HitTest in the event handler for ManipulationDelta, and then use your own logic for handling the drag over operation. Use ManipulationCompleted event to check the hit test again to complete the drop
I have implemented MouseDragElementBehavior to my application before but unfortunately I use the application now using touch panel.
Before, obviously I drag using the mouse, but now because I am using touch panel, the MouseDragElementBehavior won't work.
Is there a way to convert this? My only changes to my application is by using Touch Panel and no changes to my application at all.
The rest like what a mouse can do is also doable by touching but dragging is not supported.
Please help. Thanks
There currently isn't any official Drag for touch. You can however create your own thouch event for such by responding and combining touch events.
PreviewTouchDown For starting your own start drag function on element so add the TouchMove event here to the object
TouchMove For dragging the object visual
PreviewTouchUp For stop dragging stop the TouchMove event here
TouchEnter Check if the object you entered accept drops
Or you can of course google for libraries that already implemented this kind of behavior.
I have googled it a bit and found a good walktrought for windows applications.
And with the Touch Class you can get all the touch points in the application (multiple fingers) and implement your own behavior.
I've got a WPF app that has a WindowsFormsHost, which hosts a geobase map.
The problem I have is getting the mouse events through to the map. I've added MouseUp event handlers to the map (in code), but this does not work, and I've tried adding the MouseUp event handler on the Grid that contains the WindowsFormsHost, but the events are not picked up by this either.
I'm not sure whether this is a general WPF problem with the way I'm handling events, or a more specific problem that is specific to hosting Windows Forms apps in WPF...
Any pointers would be appreciated :)
As far as I understand you need to call WindowsFormsHost.EnableWindowsFormsInterop() for events to be forwarded to your winforms code.