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
495
RibbonTabItem in VisualTree
posted

Hi

In order to display a help screen I have to figure out what element is focused. Normally I just go up the visual tree until I come across a well-known element for which a help is defined. I thought for Ribbon this could be a RibbonTabItem. I therefore added a help-refererence for each RibbonTabItem. I assumed that as soon as I click anywhere into the Ribbon-Tab, I just have to go up the visual tree until I come across a RibbonTabItem. However, this seems not to be the case (except I'm on the tab-header). I instead bump into a XamTabControl... Can anybody explain the visual tree of the Ribbon?

Thank you!

Parents
  • 54937
    Verified Answer
    Offline posted

    TabControls (including the xamTabControl used by the xamRibbon) contain a collection of tab items. Those items are displayed within the visual tree of the tabcontrol but the template for the tab items just displays the header. The tab control itself contains a contentpresenter that displays the Content for the selected TabItem. That is why you are hitting the tab control and not the tab item as you walk up the visual tree from something within the content. Note, the Content of a ContentControl such as the TabItem (which is a HeaderedContentControl) is part of its logical tree so if you instead walked up the logical tree falling back to the visual tree then you should hit the tab item. E.g.

    DependencyObject d = startingObject;
    while (d != null && !(d is TabItem))
    {
     d = LogicalTreeHelper.GetParent(d) ?? VisualTreeHelper.GetParent(d);
    }

    if (null != d)
    {
     // do something here
    }

Reply Children