QueryContinueDrag never fires - c#

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.

Related

Implementing drag and drop in wp8.1

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.

WPF - Making DragDrop and ManipulationEnabled co-exist

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

How do I implement touch event for my application?

I want to implement touch event in my Win-Form application. Touch events for buttons, list, combo box and check box. Any idea how do I implement it ? I couldn't find any resources for the same.
I just want my application to be completely compatible with the touch screen Tablets. I use .NET 3.5 and don't see any relevant event handlers. Am I missing any thing ?
I think you are missing something.
I think the "touch" event you are looking for is in fact a "single click" if running win forms on a tablet.
Handle the OnClick event.
You can do so by using Selecting event handler dor respective controls

Can I use window hooks in C# to determine if a window gains or loses focus?

I've written a c# application which automates an instance of IE. I'd like to know when internet explorer gains focus and when it looses focus.
From the SHDocVw.InternetExplorer object I can get it's HWND. From there how can I create a message hook to receive WM_KILLFOCUS and WM_FOCUS events (assuming those are the correct events to be listening for :))?
Thanks everyone!!
UPDATE: I found a way I could use to accomplish the above goal without using hooks (which I haven't quite figured out how to do in c# yet), using the .NET framework in this question.
The problem with this code
AutomationFocusChangedEventHandler focusHandler
= new AutomationFocusChangedEventHandler(OnFocusChanged);
Automation.AddAutomationFocusChangedEventHandler(focusHandler);
is that it is easy for a window to be the foreground window and that event won't fire when that window is switched to because it's waiting for a specific UI Element to be in focus. (To test this you can use a function that uses that code and prints a message everytime a new window is in focus, such as the MSDN sample TrackFocus, and then click on a webbrowser. When most webpages or a blank page is being displayed in the browser the event wont fire until the address bar or some other element is selected.) It could probably work if there was a way to modify so that it could throw the event if either no UI Element is in focus or every time an element lost focus (instead being thrown when it gains focused). Anyone have any ideas on how I could fix the above code to solve my problem?
Update 2: I just came across this (article claims you can only hook to mouse and keyboard from c#) as well which may mean I can't use hooks at all for what I'd like to do.
Detailed instructions on setting up a hook from C# are here: http://support.microsoft.com/kb/318804/en-us?fr=1

Wpf hosting windows form - mouse events not getting through

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.

Categories

Resources