4

If in my wpf application there are multiple grids and a dragable user control.Can anyone suggest code that could return different grid id every time the control is dragged over different grids.

animuson
  • 53,861
  • 28
  • 137
  • 147
Aksel
  • 53
  • 3

1 Answers1

4

You can use Mouse.DirectlyOver then go up the visual tree to find the first Grid up the tree.

Mouse.DirectlyOver returns the IInputElement that is under the mouse at the time you check the property.

You can walk up the visual tree using a method described in this SO question

Edit: I found the SO question about visual tree walking i was thinking about. (much better than the first link IMHO).

Community
  • 1
  • 1
Louis Kottmann
  • 16,268
  • 4
  • 64
  • 88
  • +1 for finding me the link I looked at a long time ago about navigating WPF's visual tree. I've actually made some changes to that code and re-posted it on my blog, but I couldn't find the source of it to give them credit for it. – Rachel Dec 07 '11 at 18:06
  • @Rachel I googled the comments i had in my code, and took the first SO result =) – Louis Kottmann Dec 07 '11 at 20:07