Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            events.Clear();

            var header   = GetTemplateChild("PART_Header");
            var splitter = GetTemplateChild("PART_Splitter");
            var all      = GetTemplateChild("PART_BUTTON");

            events["1"] = all != null?all.MouseHovering().Subscribe(x => IsHovering = x) : null;

            events["HLBD"] = header != null?header.MouseDown().Where(x => x.ChangedButton == MouseButton.Left).Subscribe(x =>
            {
                if (IsOpen)
                {
                    PopupManager.Tracking = false;
                }
                else if (HasItems && !IsSplitButton)
                {
                    PopupManager.Enter(this, true);
                }
            }) : null;

            events["2"] = header != null?header.MouseClicks().Subscribe(x => OnClick()) : null;

            events["3"] = header != null?header.MousePressed().Subscribe(x => IsPressed = this.IsPressed()) : null;

            events["5"] = splitter != null?splitter.MouseHovering().Subscribe(x => IsHoveringSplitter = x) : null;

            events["4"] = splitter != null?splitter.MouseDown().Where(x => x.ChangedButton == MouseButton.Left).Subscribe(x => PopupManager.OpenedItem = this) : null;
        }