private void Show() { // Check whether the window is still active // (it prevent keytips showing during Alt-Tab'ing) if (!this.window.IsActive) { this.RestoreFocuses(); return; } this.currentUserInput = string.Empty; this.activeAdornerChain = new KeyTipAdorner(this.ribbon, this.ribbon, null); this.activeAdornerChain.Terminated += this.OnAdornerChainTerminated; // Special behavior for backstage var backstage = this.ribbon.Menu as Backstage; if (backstage != null && backstage.IsOpen) { var keys = KeyTip.GetKeys(backstage); if (!String.IsNullOrEmpty(keys)) { this.activeAdornerChain.Forward(KeyTip.GetKeys(backstage), false); } else { this.activeAdornerChain.Attach(); } } else { this.activeAdornerChain.Attach(); } }
// Find key tips on the given element private void FindKeyTips(UIElement element, bool hide) { this.Log("FindKeyTips"); IEnumerable children = LogicalTreeHelper.GetChildren(element); foreach (object item in children) { UIElement child = item as UIElement; RibbonGroupBox groupBox = (child as RibbonGroupBox); if (child != null) { string keys = KeyTip.GetKeys(child); if (keys != null) { // Gotcha! KeyTip keyTip = new KeyTip { Content = keys, Visibility = hide ? Visibility.Collapsed : Visibility.Visible }; // Add to list & visual // children collections keyTips.Add(keyTip); base.AddVisualChild(keyTip); associatedElements.Add(child); if (groupBox != null) { if (groupBox.State == RibbonGroupBoxState.Collapsed) { keyTip.Visibility = Visibility.Visible; FindKeyTips(child, true); continue; } else { keyTip.Visibility = Visibility.Collapsed; } } else { // Bind IsEnabled property Binding binding = new Binding("IsEnabled") { Source = child, Mode = BindingMode.OneWay }; keyTip.SetBinding(UIElement.IsEnabledProperty, binding); continue; } } if ((groupBox != null) && (groupBox.State == RibbonGroupBoxState.Collapsed)) { FindKeyTips(child, true); } else { FindKeyTips(child, hide); } } } }