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.
Asked
Active
Viewed 106 times
4
-
1Doesn't your grid have a name? – peer Dec 07 '11 at 17:46
-
Well it does not matter gridid or grid name. Can i get that as return value when i drag and drop it over that grid? – Aksel Dec 07 '11 at 17:51
-
@peer: he wants the element under the mouse, how does naming grids helps in any way? – Louis Kottmann Dec 07 '11 at 17:53
-
I didn't get the question right, I thought he did not know which property he could use – peer Dec 07 '11 at 17:57
1 Answers
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