private static void OnIsDisabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        if (d is UIElement element)
        {
            if ((bool)e.NewValue)
            {
                element.PreviewMouseWheel += ScrollViewerPreviewMouseWheel;
            }
            else
            {
                element.PreviewMouseWheel -= ScrollViewerPreviewMouseWheel;
            }
        }

        void ScrollViewerPreviewMouseWheel(object sender, MouseWheelEventArgs args)
        {
            if (args.Handled)
            {
                return;
            }

            args.Handled = true;

            if (VisualHelper.GetParent <System.Windows.Controls.ScrollViewer>((UIElement)sender) is { } scrollViewer)
            {
                scrollViewer.RaiseEvent(new MouseWheelEventArgs(args.MouseDevice, args.Timestamp, args.Delta)
                {
                    RoutedEvent = UIElement.MouseWheelEvent,
                    Source      = sender
                });
            }
        }
    }
示例#2
0
    public override Style SelectStyle(object item, DependencyObject container)
    {
        if (container is TabItem tabItem && VisualHelper.GetParent <TabControl>(tabItem) is { } tabControl)
        {
            var count = tabControl.Items.Count;
            if (count == 1)
            {
                return(ResourceHelper.GetResourceInternal <Style>(ResourceToken.TabItemCapsuleSingle));
            }

            var index = tabControl.ItemContainerGenerator.IndexFromContainer(tabItem);
            return(index == 0
                ? ResourceHelper.GetResourceInternal <Style>(
                       tabControl.TabStripPlacement == Dock.Top || tabControl.TabStripPlacement == Dock.Bottom
                        ? ResourceToken.TabItemCapsuleHorizontalFirst
                        : ResourceToken.TabItemCapsuleVerticalFirst)
                : ResourceHelper.GetResourceInternal <Style>(index == count - 1
                    ? tabControl.TabStripPlacement == Dock.Top || tabControl.TabStripPlacement == Dock.Bottom
                        ? ResourceToken.TabItemCapsuleHorizontalLast
                        : ResourceToken.TabItemCapsuleVerticalLast
                    : ResourceToken.TabItemCapsuleDefault));
        }

        return(null);
    }
示例#3
0
        private static void Popup_Opened(object sender, EventArgs e)
        {
            var popup = (Popup)sender;

            if (popup.TemplatedParent is MenuItem menuItem)
            {
                var topLine = GetTopLine(menuItem);
                if (topLine == null)
                {
                    return;
                }

                topLine.HorizontalAlignment = HorizontalAlignment.Left;
                topLine.Width  = menuItem.ActualWidth;
                topLine.Margin = new Thickness();

                var positionLeftTop     = menuItem.PointToScreen(new Point());
                var positionRightBottom = menuItem.PointToScreen(new Point(menuItem.ActualWidth, menuItem.ActualHeight));
                ScreenHelper.FindMonitorRectsFromPoint(InteropMethods.GetCursorPos(), out _, out var workAreaRect);
                var panel = VisualHelper.GetParent <Panel>(topLine);

                if (positionLeftTop.X < 0)
                {
                    topLine.Margin = new Thickness(positionLeftTop.X - panel.Margin.Left, 0, 0, 0);
                }
                else if (positionLeftTop.X + panel.ActualWidth > workAreaRect.Right)
                {
                    var overflowWidth = positionRightBottom.X - workAreaRect.Right;
                    if (overflowWidth > 0)
                    {
                        topLine.Width -= overflowWidth + panel.Margin.Right;
                    }
                    topLine.HorizontalAlignment = HorizontalAlignment.Left;
                    topLine.Margin = new Thickness(positionLeftTop.X + panel.ActualWidth - workAreaRect.Right + panel.Margin.Right, 0, 0, 0);
                }

                if (positionRightBottom.Y > workAreaRect.Bottom)
                {
                    topLine.Width = 0;
                    topLine.HorizontalAlignment = HorizontalAlignment.Stretch;
                    topLine.Margin = new Thickness();
                }
            }
        }
    public override Style SelectStyle(object item, DependencyObject container)
    {
        if (container is ComboBoxItem comboBoxItem && VisualHelper.GetParent <ComboBox>(comboBoxItem) is { } comboBox)
        {
            var count = comboBox.Items.Count;
            if (count == 1)
            {
                return(ResourceHelper.GetResourceInternal <Style>(ResourceToken.ComboBoxItemCapsuleSingle));
            }

            var index = comboBox.ItemContainerGenerator.IndexFromContainer(comboBoxItem);
            return(index == 0
                ? ResourceHelper.GetResourceInternal <Style>(ResourceToken.ComboBoxItemCapsuleHorizontalFirst)
                : ResourceHelper.GetResourceInternal <Style>(index == count - 1
                    ? ResourceToken.ComboBoxItemCapsuleHorizontalLast
                    : ResourceToken.ComboBoxItemCapsuleDefault));
        }

        return(null);
    }