Windows Phone 7.1 (Mang), SL4, VS 2010/Expression Blend.
I have a UI element (an ellipse) that I’ve added the behavior MouseDragElementBehavior to so now I can drag my ellipse all over my other elements. Great. What I can’t figure out is how to determine where (what other UI element, specifically in this case a canvas) it was dropped on. Imagine a game board where you click and drag a piece from one square to another.
How can I determine if it’s been “dropped” on another element?
The VisualTreeHelper class contains a method FindElementsInHostCoordinates to which you can pass the Point or Rect location of your Ellipse and then get all the Controls that exist in that location and act accordingly.
You might find the remarks section in FindElementsInHostCoordinates useful.
I think you can use that method no problem in basic scenarios. I used it for a while in one of my application’s then I decided to use a manual method where I just loop over the controls and checking whether an intersection (or Point containment) occurs. Then just get the first control that is hit.
Please tell me if you have reached a better solution because I’m looking for ideas better than what I have already done! Thanks.