protected override void OnPreviewMouseWheel(MouseWheelEventArgs e) { if (PopupManager.Tracking || IsPinning) { cumulativeWheelDelta += e.Delta; if (Math.Abs(cumulativeWheelDelta) > MouseWheelSelectionChangeThreshold) { bool forward = cumulativeWheelDelta < 0; cumulativeWheelDelta = 0; IPopupItem selected = null; if (PopupManager.Tracking) { if (PopupManager.HighlightedItem != null) { var p = PopupManager.HighlightedItem; while (p.ParentItem != null) { p = p.ParentItem; } selected = p; } } else { var item = PinnedItem; selected = IsItemItsOwnContainer(item) ? (IPopupItem)item : (IPopupItem)ItemContainerGenerator.ContainerFromItem(item); } IPopupItem next = null; if (selected != null) { next = selected .PopupSiblings(forward, false) .Where(x => PopupManager.Tracking || x is RibbonItem) .FirstOrDefault(); } else { next = this.PopupChildren() .Where(x => PopupManager.Tracking || x is RibbonItem) .FirstOrDefault(); } if (next != null && next != selected) { e.Handled = true; if (PopupManager.Tracking) { PopupManager.Enter(next, true); } else { PinnedItem = ItemContainerGenerator.ItemFromContainer((DependencyObject)next); } } } } base.OnPreviewMouseWheel(e); }
public static IPopupItem NavigateSibling(this IPopupItem item, bool forward, bool cycle) { return(item.PopupSiblings(forward, cycle).SelectableItem().FirstOrDefault().NavigateItem()); }