private RibbonTabHeader GetTabHeader(RibbonTab tab) { Ribbon ribbon = tab.Ribbon; if (ribbon != null) { int index = ribbon.ItemContainerGenerator.IndexFromContainer(tab); if (index >= 0) { var grid = VisualTreeHelper.GetChild(ribbon, 0); RibbonTabHeaderItemsControl headerItemsControl = null; for (var i = 0; i < VisualTreeHelper.GetChildrenCount(grid) && headerItemsControl == null; i++) { headerItemsControl = VisualTreeHelper.GetChild(grid, i) as RibbonTabHeaderItemsControl; } if (headerItemsControl != null) { return(headerItemsControl.ItemContainerGenerator.ContainerFromIndex(index) as RibbonTabHeader); } } } return(null); }
/// <summary> /// This method is invoked when the IsItemsHost property changes. /// </summary> /// <param name="oldIsItemsHost">The old value of the IsItemsHost property.</param> /// <param name="newIsItemsHost">The new value of the IsItemsHost property.</param> protected override void OnIsItemsHostChanged(bool oldIsItemsHost, bool newIsItemsHost) { base.OnIsItemsHostChanged(oldIsItemsHost, newIsItemsHost); if (newIsItemsHost) { RibbonTabHeaderItemsControl tabHeaderItemsControl = ParentTabHeaderItemsControl; if (tabHeaderItemsControl != null) { IItemContainerGenerator generator = tabHeaderItemsControl.ItemContainerGenerator as IItemContainerGenerator; if (generator != null && generator.GetItemContainerGeneratorForPanel(this) == generator) { tabHeaderItemsControl.InternalItemsHost = this; } } } else { RibbonTabHeaderItemsControl tabHeaderItemsControl = ParentTabHeaderItemsControl; if (tabHeaderItemsControl != null && tabHeaderItemsControl.InternalItemsHost == this) { tabHeaderItemsControl.InternalItemsHost = null; } } }
public override void OnApplyTemplate() { base.OnApplyTemplate(); RibbonTabHeaderItemsControl tabItems = this.FindName("TabHeaderItemsControl") as RibbonTabHeaderItemsControl; int lastClickTime = 0; if (tabItems != null) { tabItems.PreviewMouseDown += (_, e) => { // A continuous click was made (>= 2 clicks minimizes the control) if (Environment.TickCount - lastClickTime < 300) { // here the control should be minimized if (!IsMinimizable) { IsMinimized = false; } } lastClickTime = Environment.TickCount; } } ; }
public RibbonTabHeaderItemsControlAutomationPeer(RibbonTabHeaderItemsControl owner) : base(owner) { }
protected virtual void OnActivatingKeyTip(ActivatingKeyTipEventArgs e) { if (e.OriginalSource == this) { e.KeyTipHorizontalPlacement = KeyTipHorizontalPlacement.KeyTipCenterAtTargetCenter; e.KeyTipVerticalPlacement = KeyTipVerticalPlacement.KeyTipCenterAtTargetCenter; e.KeyTipHorizontalOffset = e.KeyTipVerticalOffset = 0; Ribbon ribbon = Ribbon; if (ribbon != null) { RibbonTabHeaderItemsControl tabHeaderItemsControl = ribbon.RibbonTabHeaderItemsControl; if (tabHeaderItemsControl != null && tabHeaderItemsControl.IsVisible) { GeneralTransform headerToItemsControl = TransformToAncestor(tabHeaderItemsControl); if (headerToItemsControl != null) { Point tabHeaderOrigin = headerToItemsControl.Transform(new Point()); double tabHeaderCenterX = tabHeaderOrigin.X + (ActualWidth / 2); if (DoubleUtil.LessThan(tabHeaderCenterX, 0) || DoubleUtil.GreaterThan(tabHeaderCenterX, tabHeaderItemsControl.ActualWidth)) { e.KeyTipVisibility = Visibility.Hidden; } else { GeneralTransform itemsControlToRibbon = tabHeaderItemsControl.TransformToAncestor(ribbon); if (itemsControlToRibbon != null) { Point tabHeaderItemsControlOrigin = itemsControlToRibbon.Transform(new Point()); double horizontalOffset = tabHeaderCenterX + tabHeaderItemsControlOrigin.X; if (DoubleUtil.LessThan(horizontalOffset, 0) || DoubleUtil.GreaterThan(horizontalOffset, ribbon.ActualWidth)) { e.KeyTipVisibility = Visibility.Hidden; } else { // Determine the position of keytip with respect to Ribbon, // so that it does not get clipped. e.KeyTipHorizontalOffset = horizontalOffset; e.KeyTipVerticalOffset = tabHeaderItemsControlOrigin.Y + tabHeaderOrigin.Y + ActualHeight + KeyTipVerticalOffset; e.KeyTipHorizontalPlacement = KeyTipHorizontalPlacement.KeyTipCenterAtTargetLeft; e.KeyTipVerticalPlacement = KeyTipVerticalPlacement.KeyTipCenterAtTargetTop; e.PlacementTarget = ribbon; } } else { e.KeyTipVisibility = Visibility.Hidden; } } } else { e.KeyTipVisibility = Visibility.Hidden; } } } } }