Example #1
0
 public void GetViewIndexRange(bool includePartial, out int firstIndex, out int lastIndex)
 {
     if (this.Items.Count > 0)
     {
         firstIndex = 0;
         lastIndex  = this.Items.Count - 1;
         if (this.scrollViewer == null || this.Items.Count <= 1)
         {
             return;
         }
         Thickness          thickness           = new Thickness(this.scrollViewer.BorderThickness.Left + this.scrollViewer.Padding.Left, this.scrollViewer.BorderThickness.Top + this.scrollViewer.Padding.Top, this.scrollViewer.BorderThickness.Right + this.scrollViewer.Padding.Right, this.scrollViewer.BorderThickness.Bottom + this.scrollViewer.Padding.Bottom);
         Rect               rect1               = this.scrollViewer.TransformToVisual(Application.Current.RootVisual).TransformBounds(new Rect(new Point(0.0, 0.0), this.scrollViewer.RenderSize));
         ReorderListBoxItem reorderListBoxItem1 = VisualTreeHelper.FindElementsInHostCoordinates(ReorderListBox.GetHostCoordinates(new Point(rect1.Left + thickness.Left, rect1.Top + thickness.Top)), (UIElement)this.scrollViewer).OfType <ReorderListBoxItem>().FirstOrDefault <ReorderListBoxItem>();
         if (reorderListBoxItem1 != null)
         {
             Rect rect2 = reorderListBoxItem1.TransformToVisual(Application.Current.RootVisual).TransformBounds(new Rect(new Point(0.0, 0.0), reorderListBoxItem1.RenderSize));
             firstIndex = this.ItemContainerGenerator.IndexFromContainer((DependencyObject)reorderListBoxItem1);
             if (!includePartial && firstIndex < this.Items.Count - 1 && (rect2.Top < rect1.Top && rect2.Bottom < rect1.Bottom))
             {
                 firstIndex = firstIndex + 1;
             }
         }
         ReorderListBoxItem reorderListBoxItem2 = VisualTreeHelper.FindElementsInHostCoordinates(ReorderListBox.GetHostCoordinates(new Point(rect1.Left + thickness.Left, rect1.Bottom - thickness.Bottom - 1.0)), (UIElement)this.scrollViewer).OfType <ReorderListBoxItem>().FirstOrDefault <ReorderListBoxItem>();
         if (reorderListBoxItem2 == null)
         {
             return;
         }
         Rect rect3 = reorderListBoxItem2.TransformToVisual(Application.Current.RootVisual).TransformBounds(new Rect(new Point(0.0, 0.0), reorderListBoxItem2.RenderSize));
         lastIndex = this.ItemContainerGenerator.IndexFromContainer((DependencyObject)reorderListBoxItem2);
         if (includePartial || lastIndex <= firstIndex || (rect3.Bottom <= rect1.Bottom || rect3.Top <= rect1.Top))
         {
             return;
         }
         lastIndex = lastIndex - 1;
     }
     else
     {
         firstIndex = -1;
         lastIndex  = -1;
     }
 }
Example #2
0
        private void UpdateDropTarget(double dragItemOffset, bool showTransition)
        {
            // ISSUE: explicit reference operation
            // ISSUE: explicit reference operation
            ReorderListBoxItem targetItemContainer = (ReorderListBoxItem)Enumerable.FirstOrDefault <ReorderListBoxItem>(Enumerable.OfType <ReorderListBoxItem>((IEnumerable)VisualTreeHelper.FindElementsInHostCoordinates(ReorderListBox.GetHostCoordinates(new Point(((Rect)this.dragInterceptorRect).Left, ((Rect)this.dragInterceptorRect).Top + dragItemOffset)), (UIElement)this.itemsPanel)));

            if (targetItemContainer == null)
            {
                return;
            }
            Rect rect = ((UIElement)targetItemContainer.DragHandle).TransformToVisual((UIElement)this.dragInterceptor).TransformBounds(new Rect(new Point(0.0, 0.0), ((UIElement)targetItemContainer.DragHandle).RenderSize));
            // ISSUE: explicit reference operation
            // ISSUE: explicit reference operation
            double             num1  = (rect.Top + rect.Bottom) / 2.0;
            int                num2  = ((PresentationFrameworkCollection <UIElement>) this.itemsPanel.Children).IndexOf((UIElement)targetItemContainer);
            int                count = ((PresentationFrameworkCollection <UIElement>) this.itemsPanel.Children).Count;
            bool               after = dragItemOffset > num1;
            ReorderListBoxItem reorderListBoxItem1 = null;

            if (!after && num2 > 0)
            {
                ReorderListBoxItem reorderListBoxItem2 = (ReorderListBoxItem)((PresentationFrameworkCollection <UIElement>) this.itemsPanel.Children)[num2 - 1];
                if ((string)(((FrameworkElement)reorderListBoxItem2).Tag as string) == "DropAfterIndicator")
                {
                    reorderListBoxItem1 = reorderListBoxItem2;
                }
            }
            else if (after && num2 < count - 1)
            {
                ReorderListBoxItem reorderListBoxItem2 = (ReorderListBoxItem)((PresentationFrameworkCollection <UIElement>) this.itemsPanel.Children)[num2 + 1];
                if ((string)(((FrameworkElement)reorderListBoxItem2).Tag as string) == "DropBeforeIndicator")
                {
                    reorderListBoxItem1 = reorderListBoxItem2;
                }
            }
            if (reorderListBoxItem1 == null)
            {
                targetItemContainer.DropIndicatorHeight = ((FrameworkElement)this.dragIndicator).Height;
                string str = after ? "DropAfterIndicator" : "DropBeforeIndicator";
                VisualStateManager.GoToState((Control)targetItemContainer, str, showTransition);
                ((FrameworkElement)targetItemContainer).Tag = str;
                reorderListBoxItem1 = targetItemContainer;
            }
            for (int index = num2 - 5; index <= num2 + 5; ++index)
            {
                if (index >= 0 && index < count)
                {
                    ReorderListBoxItem reorderListBoxItem2 = (ReorderListBoxItem)((PresentationFrameworkCollection <UIElement>) this.itemsPanel.Children)[index];
                    if (reorderListBoxItem2 != reorderListBoxItem1)
                    {
                        VisualStateManager.GoToState((Control)reorderListBoxItem2, "NoDropIndicator", showTransition);
                        ((FrameworkElement)reorderListBoxItem2).Tag = ("NoDropIndicator");
                    }
                }
            }
            this.UpdateDropTargetIndex(targetItemContainer, after);
        }
Example #3
0
        private void UpdateDropTarget(double dragItemOffset, bool showTransition)
        {
            ReorderListBoxItem targetItemContainer = VisualTreeHelper.FindElementsInHostCoordinates(ReorderListBox.GetHostCoordinates(new Point(this.dragInterceptorRect.Left, this.dragInterceptorRect.Top + dragItemOffset)), (UIElement)this.itemsPanel).OfType <ReorderListBoxItem>().FirstOrDefault <ReorderListBoxItem>();

            if (targetItemContainer == null)
            {
                return;
            }
            Rect               rect  = targetItemContainer.DragHandle.TransformToVisual((UIElement)this.dragInterceptor).TransformBounds(new Rect(new Point(0.0, 0.0), targetItemContainer.DragHandle.RenderSize));
            double             num1  = (rect.Top + rect.Bottom) / 2.0;
            int                num2  = this.itemsPanel.Children.IndexOf((UIElement)targetItemContainer);
            int                count = this.itemsPanel.Children.Count;
            bool               after = dragItemOffset > num1;
            ReorderListBoxItem reorderListBoxItem1 = (ReorderListBoxItem)null;

            if (!after && num2 > 0)
            {
                ReorderListBoxItem reorderListBoxItem2 = (ReorderListBoxItem)this.itemsPanel.Children[num2 - 1];
                if (reorderListBoxItem2.Tag as string == "DropAfterIndicator")
                {
                    reorderListBoxItem1 = reorderListBoxItem2;
                }
            }
            else if (after && num2 < count - 1)
            {
                ReorderListBoxItem reorderListBoxItem2 = (ReorderListBoxItem)this.itemsPanel.Children[num2 + 1];
                if (reorderListBoxItem2.Tag as string == "DropBeforeIndicator")
                {
                    reorderListBoxItem1 = reorderListBoxItem2;
                }
            }
            if (reorderListBoxItem1 == null)
            {
                targetItemContainer.DropIndicatorHeight = this.dragIndicator.Height;
                string stateName = after ? "DropAfterIndicator" : "DropBeforeIndicator";
                VisualStateManager.GoToState((Control)targetItemContainer, stateName, showTransition);
                targetItemContainer.Tag = (object)stateName;
                reorderListBoxItem1     = targetItemContainer;
            }
            for (int index = num2 - 5; index <= num2 + 5; ++index)
            {
                if (index >= 0 && index < count)
                {
                    ReorderListBoxItem reorderListBoxItem2 = (ReorderListBoxItem)this.itemsPanel.Children[index];
                    if (reorderListBoxItem2 != reorderListBoxItem1)
                    {
                        VisualStateManager.GoToState((Control)reorderListBoxItem2, "NoDropIndicator", showTransition);
                        reorderListBoxItem2.Tag = (object)"NoDropIndicator";
                    }
                }
            }
            this.UpdateDropTargetIndex(targetItemContainer, after);
        }
Example #4
0
        private void dragInterceptor_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            this.scrollViewer.VerticalScrollBarVisibility = ((ScrollBarVisibility)0);
            if (this.dragItem != null)
            {
                return;
            }
            e.Handled = true;
            if (this.itemsPanel == null)
            {
                this.itemsPanel = (Panel)VisualTreeHelper.GetChild((DependencyObject)((ContentControl)this.scrollViewer).Content, 0);
            }
            this._isManipulating = true;
            GeneralTransform   visual             = ((UIElement)this.dragInterceptor).TransformToVisual(Application.Current.RootVisual);
            List <UIElement>   list               = (List <UIElement>)Enumerable.ToList <UIElement>(VisualTreeHelper.FindElementsInHostCoordinates(ReorderListBox.GetHostCoordinates(visual.Transform(e.ManipulationOrigin)), (UIElement)this.itemsPanel));
            ReorderListBoxItem reorderListBoxItem = (ReorderListBoxItem)Enumerable.FirstOrDefault <ReorderListBoxItem>(Enumerable.OfType <ReorderListBoxItem>((IEnumerable)list));

            if (reorderListBoxItem == null || !list.Contains((UIElement)reorderListBoxItem.DragHandle))
            {
                return;
            }
            VisualStateManager.GoToState((Control)reorderListBoxItem, "Dragging", true);
            Point point = ((UIElement)reorderListBoxItem).TransformToVisual((UIElement)this.dragInterceptor).Transform(new Point(0.0, 0.0));

            // ISSUE: explicit reference operation
            Canvas.SetLeft((UIElement)this.dragIndicator, ((Point)@point).X);
            // ISSUE: explicit reference operation
            Canvas.SetTop((UIElement)this.dragIndicator, ((Point)@point).Y);
            Image dragIndicator1 = this.dragIndicator;
            Size  renderSize1    = ((UIElement)reorderListBoxItem).RenderSize;
            // ISSUE: explicit reference operation
            double width = ((Size)@renderSize1).Width;

            ((FrameworkElement)dragIndicator1).Width = width;
            Image dragIndicator2 = this.dragIndicator;
            Size  renderSize2    = ((UIElement)reorderListBoxItem).RenderSize;
            // ISSUE: explicit reference operation
            double height = ((Size)@renderSize2).Height;

            ((FrameworkElement)dragIndicator2).Height = height;
            this.dragItemContainer   = reorderListBoxItem;
            this.dragItem            = ((ContentControl)this.dragItemContainer).Content;
            this.isDragItemSelected  = this.dragItemContainer.IsSelected;
            this.dragInterceptorRect = visual.TransformBounds(new Rect(new Point(0.0, 0.0), ((UIElement)this.dragInterceptor).RenderSize));
            this.dropTargetIndex     = -1;
        }
Example #5
0
        private void dragInterceptor_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            this.scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled;
            if (this.dragItem != null)
            {
                return;
            }
            e.Handled = true;
            if (this.itemsPanel == null)
            {
                this.itemsPanel = (Panel)VisualTreeHelper.GetChild((DependencyObject)this.scrollViewer.Content, 0);
            }
            this._isManipulating = true;
            GeneralTransform   visual             = this.dragInterceptor.TransformToVisual(Application.Current.RootVisual);
            List <UIElement>   list               = VisualTreeHelper.FindElementsInHostCoordinates(ReorderListBox.GetHostCoordinates(visual.Transform(e.ManipulationOrigin)), (UIElement)this.itemsPanel).ToList <UIElement>();
            ReorderListBoxItem reorderListBoxItem = list.OfType <ReorderListBoxItem>().FirstOrDefault <ReorderListBoxItem>();

            if (reorderListBoxItem == null || !list.Contains((UIElement)reorderListBoxItem.DragHandle))
            {
                return;
            }
            VisualStateManager.GoToState((Control)reorderListBoxItem, "Dragging", true);
            Point point = reorderListBoxItem.TransformToVisual((UIElement)this.dragInterceptor).Transform(new Point(0.0, 0.0));

            Canvas.SetLeft((UIElement)this.dragIndicator, point.X);
            Canvas.SetTop((UIElement)this.dragIndicator, point.Y);
            this.dragIndicator.Width  = reorderListBoxItem.RenderSize.Width;
            this.dragIndicator.Height = reorderListBoxItem.RenderSize.Height;
            this.dragItemContainer    = reorderListBoxItem;
            this.dragItem             = this.dragItemContainer.Content;
            this.isDragItemSelected   = this.dragItemContainer.IsSelected;
            this.dragInterceptorRect  = visual.TransformBounds(new Rect(new Point(0.0, 0.0), this.dragInterceptor.RenderSize));
            this.dropTargetIndex      = -1;
        }