This question is locked. New answers and comments are not allowed.
I'm having an issue related to RadContextMenus and the VisualTreeHelper.FindElementsInHostCoordinates method (more specifically with submenus). I understand that the RadContextMenu implementation uses the Silverlight Popup control, and that by default Popups are not added to the VisualTree and therefore child elements of the Popup CANNOT be detected using the VisualTreeHelper. If however the Popup is part of the VisualTree the VisualTreeHelper should be able to detect child elements without issue.
So, as an attempted fix I programmatically attached the RadContextMenu's hosting Popup to the RootVisual - this worked great for all immediate menu items, however submenus and their child menuitems still could NOT be detected by the VisualTreeHelper. As it turns out submenus are actually hosted in another Popup.
The visual heirarchy (minus irrelevant elements) is roughly:
-Popup
-RadContextMenu
-RadMenuItem
-Popup
-RadMenuItem
-...
-RadMenuItem
-...
This also means that the submenu's Popup IS implicitly attached to the VisualTree - so the question is why doesn't this work? The best I can guess is that for some reason the Silverlight VisualTreeHelper is unable to detect Popups (and their child elements) that are hosted in other Popups regardless of whether or not they are attached to the VisualTree.
Basically, my application requires that given an arbitrary x/y position, we can find the topmost control at that point. VisualTreeHelper.FindElementsInHostCoordinates works perfectly in all situations except for the one described above.
This leaves me with a few questions:
- Is there a way to ensure all RadContextMenu submenus and child menuitems can be detected using the VisualTreeHelper.FindElementsInHostCoordinates method?
- Is there perhaps another reliable method that would fulfill my application requirements and still use the RadContextMenu?
- Is there a reason why submenus use another Popup as opposed to a something like a Canvas?
- Is there a reason why RadContextMenus are not automatically attached to the VisualTree in the same manner as RadWindows (via Telerik.Windows.Controls.HACKS.AttachPopupToVisualTree)?
Thanks!
So, as an attempted fix I programmatically attached the RadContextMenu's hosting Popup to the RootVisual - this worked great for all immediate menu items, however submenus and their child menuitems still could NOT be detected by the VisualTreeHelper. As it turns out submenus are actually hosted in another Popup.
The visual heirarchy (minus irrelevant elements) is roughly:
-Popup
-RadContextMenu
-RadMenuItem
-Popup
-RadMenuItem
-...
-RadMenuItem
-...
This also means that the submenu's Popup IS implicitly attached to the VisualTree - so the question is why doesn't this work? The best I can guess is that for some reason the Silverlight VisualTreeHelper is unable to detect Popups (and their child elements) that are hosted in other Popups regardless of whether or not they are attached to the VisualTree.
Basically, my application requires that given an arbitrary x/y position, we can find the topmost control at that point. VisualTreeHelper.FindElementsInHostCoordinates works perfectly in all situations except for the one described above.
This leaves me with a few questions:
- Is there a way to ensure all RadContextMenu submenus and child menuitems can be detected using the VisualTreeHelper.FindElementsInHostCoordinates method?
- Is there perhaps another reliable method that would fulfill my application requirements and still use the RadContextMenu?
- Is there a reason why submenus use another Popup as opposed to a something like a Canvas?
- Is there a reason why RadContextMenus are not automatically attached to the VisualTree in the same manner as RadWindows (via Telerik.Windows.Controls.HACKS.AttachPopupToVisualTree)?
Thanks!