This is a migrated thread and some comments may be shown as answers.

RadContextMenu and VisualTreeHelper.FindElementsInHostCoordinates

3 Answers 112 Views
Menu
This is a migrated thread and some comments may be shown as answers.
GT
Top achievements
Rank 1
GT asked on 26 Jan 2010, 09:26 PM
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!

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 27 Jan 2010, 12:48 PM
Hi Greg,

RadContextMenu is not added to the visual tree because it doesn't need to. In Silverlight 2 we had to do it because of bug in the framework. Also there is a chance that AttachPopupToVisualTree method won't succeed.
We do not expose public method to iterate through popups so there is no way to detect the visual elements in some coordinates.
SubMenuItems use popup because it is natural - you want the newly opened submenu to be on top of the other elements - including Windows.
We may consider adding such method in future release.

Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
GT
Top achievements
Rank 1
answered on 27 Jan 2010, 05:03 PM
Hi Hristo,

Thanks for the quick response.

I believe the issue is moreso that the Silverlight implementation of VisualTreeHelper doesn't play nicely with Popups inside of other Popups. Is it possible to specify a different Style/ControlTemplate for the RadContextMenu which would replace the submenu Popup with a control that will work with VisualTreeHelper?

Thanks -
0
Hristo
Telerik team
answered on 28 Jan 2010, 12:10 PM
Hello Greg,

Changing how RadMenuItem works is not an easy task. Popup is essential part of RadMenuItem and I'm afraid it won't work without it.
However I've managed to create a prototype that will take Popups in account when calling VisualTreeHelper.FindElementsInHostCoordinates.

Take a look and let me know if this will work for you.

Regards,
Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Menu
Asked by
GT
Top achievements
Rank 1
Answers by
Hristo
Telerik team
GT
Top achievements
Rank 1
Share this question
or