Skip to main content

Microsoft Silverlight

Answered Question Drag and Drop / Hit DetectionRSS Feed

(0)

Aaron Edwards
Aaron Ed...

Member

Member

39 points

60 Posts

Drag and Drop / Hit Detection

Hi,

I'm trying to detect when one object has been dragged inside another.  What's the best way to do this? 

Let's say I have two objects: ObjectA and Object B, and I want to know when ObjectA has been dragged inside of ObjectB.  Obviously I can't use ObjectB.MouseLeftButtonUp, since ObjectA is capturing the mouse at that time (it's being dragged by the user). 

I'm thinking I'll have to do some hit testing.  However, the examples I"ve seen online (http://www.andybeaulieu.com/Default.aspx?tabid=67&EntryID=95 for example), test for any intersection at all, not just for "is ObjectA entirely contained by ObjectB".

Thanks in advance for your suggestions.

Aaron

damonpayne
damonpayne

Member

Member

304 points

75 Posts

Re: Drag and Drop / Hit Detection

This might help?

http://www.damonpayne.com/2008/09/20/RunTimeIsDesignTimeForAGT7.aspx

-Damon
http://www.damonpayne.com/

Aaron Edwards
Aaron Ed...

Member

Member

39 points

60 Posts

Re: Drag and Drop / Hit Detection

Thanks, Damon. 

This looks pretty cool.  Since you wrote this yourself, you can tell me if it OnDrop fires only if the entirety of the purple couch is on the design surface (rather than half-in/half out).  I only ask because this looks to be a beta2 application, and might be a bit of work to port to the Release Version.  Thanks!

Aaron

damonpayne
damonpayne

Member

Member

304 points

75 Posts

Re: Drag and Drop / Hit Detection

The code has been updated for RTW since that particular article,

Currently the hit test uses the upper-left hand corner of the object, but it would be easy to change "HitTest" to take into account the expected RenderSize of the object.

-Damon
http://www.damonpayne.com/

Aaron Edwards
Aaron Ed...

Member

Member

39 points

60 Posts

Re: Drag and Drop / Hit Detection

Oh, checking the top-left point.  I hadn't thought of that.  That actually should solve my problem straight-off.  But I'm definitely gonig to check out your code, because it looks much cleaner than my approach.

So the zip file at the bottom of the page is the RTW version, right?

Thanks again.

Aaron

damonpayne
damonpayne

Member

Member

304 points

75 Posts

Answered Question

Re: Drag and Drop / Hit Detection

The most recent RTW code is here:

http://www.damonpayne.com/2008/10/19/RunTimeIsDesignTimeForAGT14.aspx

-Damon
http://www.damonpayne.com/
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities