wpfgridwpf-positioning

Getting wpf gridid


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.


Solution

  • 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).