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!
I'm not sure I understand the question. When you set the x:Name on the RibbonTabItem (or any other FrameworkElement in the xaml) that will set the Name property so you can still check the Name property of the RibbonTabItem that you find as you walk up the tree.
Thank you very much. That seems to work. One follow-up question though...
In order to indentify my RibbonTabItem I set a x:Name on each element. I now thought I could just check the name of a TabItem... This assumption seems to be wrong. Could you please clear this up for me?
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}
if (null != d){ // do something here}