Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
185
HitTesting
posted

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.

Parents
  • 54937
    Suggested Answer
    Offline posted

    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.

Reply Children
No Data