Search code examples
silverlightdrag-and-dropfindcontrol

Best method to find controls under a dropped usercontrol


I'm trying to implement a drag-drop function to a usercontrol.

I've managed to get this working properly with the use of google, however, when dropping a control I wish to find every similar type controls that might be or might not be under it.

My current way would be check every control and see if it's under the dropped control. But I wonder if there is a better way, like a find control function which can check for controls within a given range?


Solution

  • you could use this function: http://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.findelementsinhostcoordinates%28v=vs.95%29.aspx

    void xy_MouseMove(object sender, MouseEventArgs e)
        {
            if (m_IsDraging)
            {
                var res = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(null), elemenetWhichChildrenYouWantToCheck);
                //... check res for drop elements and react
            }
        }
    

    Or you can just use this function only in MouseLeftButtonUp event