Skip to main content
Home Forums Silverlight Programming Programming with .NET - General Drag and Drop / Hit Detection
5 replies. Latest Post by damonpayne on October 28, 2008.
(0)
Aaron Ed...
Member
39 points
60 Posts
10-27-2008 3:02 PM |
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
304 points
75 Posts
10-27-2008 4:54 PM |
This might help?
http://www.damonpayne.com/2008/09/20/RunTimeIsDesignTimeForAGT7.aspx
10-27-2008 5:46 PM |
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!
10-27-2008 5:57 PM |
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.
10-27-2008 6:14 PM |
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.
10-28-2008 12:10 PM |
The most recent RTW code is here:
http://www.damonpayne.com/2008/10/19/RunTimeIsDesignTimeForAGT14.aspx