public static int GetSelectedItemIndexAtPosition(ListBox listBox, GetPositionFromInputElementDelegate getPosition)
        {
            var index = -1;

            if (listBox?.Items != null)
            {
                for (int i = 0; i < listBox.Items.Count; ++i)
                {
                    if (listBox.SelectedItems.IndexOf(listBox.Items[i]) == -1)
                    {
                        continue;
                    }

                    var listViewItem = getListViewItem(listBox, i);

                    if (VisualTreeHelperTools.IsMouseOverTarget(listViewItem, getPosition))
                    {
                        index = i;
                        break;
                    }
                }
            }

            return(index);
        }
示例#2
0
        private static void DefaultRouteBackwardPreviewMouseWheelHandler(object sender, MouseWheelEventArgs e)
        {
            if (sender is DependencyObject d && !e.Handled)
            {
                e.Handled = true;

                var args = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
                {
                    RoutedEvent = UIElement.MouseWheelEvent,
                    Source      = e.Source,
                };

                var parent = VisualTreeHelperTools.GetParentObjectRecursive <UIElement>(d);
                parent.RaiseEvent(args);
            }
        }