0

I have a ScatterView which consist of 2 items: an Image and a RichTextBox. RichTextBox has AllowDrop set to true.

When I drag the Image to the RichTextBox, the image disappears completely but RichTextBox's DragEnter and Drop event did not fire at all. Neither did PreviewDragEnter nor PreviewDrop.

I tried setting RichTextBox's AllowDrop to false, and the Image landed on top of the RichTextBox as expected.

How do I get the DragEnter and Drop event of RichTextBox to fire? The only thing that fires is the ScatterView's Drop event.

Robert Levy
  • 28,747
  • 6
  • 62
  • 94
Darren Ng
  • 373
  • 1
  • 5
  • 20
  • The drop event is enabled by default in WPF and should be working in your code but it seems like you are not using it properly. A RichTextBox cannot hold an image, just text; so the property being dragged should be the name of the picture, what perhaps you are not doing. Could you please include the code you are trying to see what you are you doing wrong? – varocarbas Aug 05 '13 at 09:41
  • Oh ya. When I mention it didn't fire, it means it didnt reach the breakpoint in Debug mode of VS2010. The breakpoint is set at the opening { of the respective events (previewdrag, drop, ..). The drop event is working, because if I disable it, the Image will be on top of the RichTextBox instead of disappearing. The issue now is it disappeared and I have no idea where it went because all the Drop events didnt fire at all. I will try to post some code. – Darren Ng Aug 05 '13 at 09:45
  • I dealt with an equivalent issue a couple of weeks ago and you are right: you don't get the drop event to be fired (the method is apparently never reached). The reason for that is that you don't need to add this method as far as the WPF application deals with it by its own (by default), you would have to disable this automatic management (not sure how to do that; but, on the other hand, would be pointless). I am sure that your main problem is the drag part. Post the code you are trying, please. – varocarbas Aug 05 '13 at 09:52
  • Thanks for confirming it won't fire :) Are you referring to the code for handling the movement and dragging in ScatterView? There's no code for that, I didn't overwrite the ManipulationDelta method when I add the image to scatterview... – Darren Ng Aug 05 '13 at 10:05
  • There you have your problem. The drag and drop consists in two parts: dragging (events in the source control) and dropping (events in the destination control). WPF avoids the second part but you have to deal with the first part anyway. – varocarbas Aug 05 '13 at 10:18
  • I have included a sample code to help you to understand how to deal with this functionality. – varocarbas Aug 05 '13 at 10:30

1 Answers1

2

Drag & drop with Surface controls (like ScatterView) is different from normal Windows drag & drop. The thing being dragged is a 2d shape (not a single point) which could have multiple inputs dragging it around. Because of this, we couldn't shim the Surface drag drop functionality into the existing WPF drag drop APIs. Instead, you'll need to use attached events from the SurfaceDragDrop object like http://msdn.microsoft.com/en-us/library/microsoft.surface.presentation.surfacedragdrop.dragenter.aspx which are very similar to the WPF equivalents but enable Surface-friendly user experiences.

Robert Levy
  • 28,747
  • 6
  • 62
  • 94