Hi:
I'm trying to make F1 help be context sensitive in our product. The goal is to have the user be able to pint to a control on the ribbon and press the F1 button and we bring up help for that command. I've tried using the VisualTreeHelper to figure out which control I'm over, but What I'm finding is that this doesn't work for all items in a ribbon. Things like the dropdowns in the MenuTool don't have a parent or are at least not rooted to the ribbon. If I do individual control hit hesting, I loose the z depth of the control so I have to do a lot of processing to figure out which control is really the visible one.
Anyone have a thought on how to do this more elegantly (or at all)?
Thanks in advance.
Yes this is correct. In WPF, the visual tree is tied to the containing Hwnd. Things like the WPF Window and Popup have their own Hwnd so they have their own visual tree and hit testing is restricted to elements within that hwnd. If you're not capturing the mouse then the static Mouse.DirectlyOver is probably going to give you the element that the mouse is over regardless of what top level window contains it. If you (or some element) is capturing the mouse then you will probably need to use interop to get the window that the mouse is over and then use something like HwndSource.FromHwnd to get the associated HwndSource and then hit test using its RootVisual.
Thanks for your response. I finally just found it easier to monitor the MouseEnter and MouseLeave events of all of the controls that I add to a ribbon. Kind of crude, but it works. I was more expecting that all of the pieces of all of the controls that I place on a ribbon were actually part of the visual/logical trees of the ribbon.