internal bool IsVerticalOrientation() { if (_isVerticalOrientation.HasValue) { return(_isVerticalOrientation.Value); } Helpers.ItemsControlHelper ich = new Helpers.ItemsControlHelper(ListBox); StackPanel itemsHost = ich.ItemsHost as StackPanel; if (itemsHost != null) { _isVerticalOrientation = (itemsHost.Orientation == System.Windows.Controls.Orientation.Vertical); return(_isVerticalOrientation.Value); } VirtualizingStackPanel panel2 = ich.ItemsHost as VirtualizingStackPanel; _isVerticalOrientation = ((panel2 == null) || (panel2.Orientation == System.Windows.Controls.Orientation.Vertical)); return(_isVerticalOrientation.Value); }
internal bool IsOnCurrentPage(ListBoxItem item) { var itemsHostRect = Rect.Empty; var listBoxItemRect = Rect.Empty; if (_visual == null) { Helpers.ItemsControlHelper ich = new Helpers.ItemsControlHelper(ListBox); ScrollContentPresenter scp = ich.ScrollHost == null ? null : ich.ScrollHost.GetVisualDescendants().OfType <ScrollContentPresenter>().FirstOrDefault(); _visual = (ich.ScrollHost == null) ? null : ((scp == null) ? ((FrameworkElement)ich.ScrollHost) : ((FrameworkElement)scp)); } if (_visual == null) { return(true); } itemsHostRect = new Rect(0.0, 0.0, _visual.ActualWidth, _visual.ActualHeight); //ListBoxItem item = ListBox.ItemContainerGenerator.ContainerFromIndex(index) as ListBoxItem; if (item == null) { listBoxItemRect = Rect.Empty; return(false); } GeneralTransform transform = item.TransformToVisual(_visual); listBoxItemRect = new Rect(transform.Transform(new Point()), transform.Transform(new Point(item.ActualWidth, item.ActualHeight))); if (!this.IsVerticalOrientation()) { return((itemsHostRect.Left <= listBoxItemRect.Left) && (listBoxItemRect.Right <= itemsHostRect.Right)); } return((listBoxItemRect.Bottom + 100 >= itemsHostRect.Top) && (listBoxItemRect.Top - 100 <= itemsHostRect.Bottom)); //return ((itemsHostRect.Top <= listBoxItemRect.Bottom) && (listBoxItemRect.Top <= itemsHostRect.Bottom)); }