private ReorderListBox.RearrangeItemInfo[] BuildRearrangeMap(int viewFirstIndex, int viewLastIndex) { ReorderListBox.RearrangeItemInfo[] rearrangeItemInfoArray = new ReorderListBox.RearrangeItemInfo[this.Items.Count]; for (int index = 0; index < rearrangeItemInfoArray.Length; ++index) { object obj = this.Items[index]; ReorderListBox.RearrangeItemInfo rearrangeItemInfo = new ReorderListBox.RearrangeItemInfo() { Item = obj, FromIndex = index }; if (viewFirstIndex <= index && index <= viewLastIndex) { ReorderListBoxItem reorderListBoxItem = (ReorderListBoxItem)this.ItemContainerGenerator.ContainerFromIndex(index); if (reorderListBoxItem != null) { Point point = reorderListBoxItem.TransformToVisual((UIElement)this.rearrangeCanvas).Transform(new Point(0.0, 0.0)); rearrangeItemInfo.FromY = point.Y; rearrangeItemInfo.Height = reorderListBoxItem.RenderSize.Height; } } rearrangeItemInfoArray[index] = rearrangeItemInfo; } return(rearrangeItemInfoArray); }
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; }
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; } }
private ReorderListBox.RearrangeItemInfo[] BuildRearrangeMap2(ReorderListBox.RearrangeItemInfo[] map, int viewFirstIndex, int viewLastIndex) { ReorderListBox.RearrangeItemInfo[] rearrangeItemInfoArray = new ReorderListBox.RearrangeItemInfo[this.Items.Count]; for (int index = 0; index < rearrangeItemInfoArray.Length; ++index) { object item = this.Items[index]; ReorderListBox.RearrangeItemInfo rearrangeItemInfo = ((IEnumerable <ReorderListBox.RearrangeItemInfo>)map).FirstOrDefault <ReorderListBox.RearrangeItemInfo>((Func <ReorderListBox.RearrangeItemInfo, bool>)(rii => { if (rii.ToIndex < 0) { return(rii.Item == item); } return(false); })); if (rearrangeItemInfo == null) { rearrangeItemInfo = new ReorderListBox.RearrangeItemInfo() { Item = item } } ; rearrangeItemInfo.ToIndex = index; if (viewFirstIndex <= index && index <= viewLastIndex) { ReorderListBoxItem reorderListBoxItem = (ReorderListBoxItem)this.ItemContainerGenerator.ContainerFromIndex(index); if (reorderListBoxItem != null) { Point point = reorderListBoxItem.TransformToVisual((UIElement)this.rearrangeCanvas).Transform(new Point(0.0, 0.0)); rearrangeItemInfo.ToY = point.Y; rearrangeItemInfo.Height = reorderListBoxItem.RenderSize.Height; } } rearrangeItemInfoArray[index] = rearrangeItemInfo; } return(rearrangeItemInfoArray); }
private int FindViewLastIndex(int firstIndex) { int num = firstIndex; Rect rect1 = this.scrollViewer.TransformToVisual(Application.Current.RootVisual).TransformBounds(new Rect(new Point(0.0, 0.0), this.scrollViewer.RenderSize)); for (; num < this.Items.Count - 1; ++num) { ReorderListBoxItem reorderListBoxItem = (ReorderListBoxItem)this.ItemContainerGenerator.ContainerFromIndex(num + 1); if (reorderListBoxItem != null) { Rect rect2 = reorderListBoxItem.TransformToVisual(Application.Current.RootVisual).TransformBounds(new Rect(new Point(0.0, 0.0), reorderListBoxItem.RenderSize)); rect2.Intersect(rect1); if (rect2 == Rect.Empty) { break; } } else { break; } } return(num); }
private void AnimateDrop(ReorderListBoxItem itemContainer) { Rect rect = itemContainer.TransformToVisual((UIElement)this.dragInterceptor).TransformBounds(new Rect(new Point(0.0, 0.0), itemContainer.RenderSize)); double num = Math.Abs(rect.Y - Canvas.GetTop((UIElement)this.dragIndicator) - ((TranslateTransform)this.dragIndicator.RenderTransform).Y); if (num > 0.0) { TimeSpan timeSpan = TimeSpan.FromSeconds(0.25 * num / rect.Height); Storyboard storyboard = new Storyboard(); DoubleAnimation doubleAnimation = new DoubleAnimation(); Storyboard.SetTarget((Timeline)doubleAnimation, (DependencyObject)this.dragIndicator.RenderTransform); Storyboard.SetTargetProperty((Timeline)doubleAnimation, new PropertyPath((object)TranslateTransform.YProperty)); doubleAnimation.To = new double?(rect.Y - Canvas.GetTop((UIElement)this.dragIndicator)); doubleAnimation.Duration = (Duration)timeSpan; storyboard.Children.Add((Timeline)doubleAnimation); EventHandler eventHandler = (EventHandler)((param0, param1) => { this.dragItem = null; itemContainer.Opacity = 1.0; this.dragIndicator.Visibility = Visibility.Collapsed; this.dragIndicator.Source = null; ((TranslateTransform)this.dragIndicator.RenderTransform).Y = 0.0; VisualStateManager.GoToState((Control)itemContainer, "NotDragging", true); }); storyboard.Completed += eventHandler; storyboard.Begin(); } else { this.dragItem = null; itemContainer.Opacity = 1.0; this.dragIndicator.Visibility = Visibility.Collapsed; this.dragIndicator.Source = null; VisualStateManager.GoToState((Control)itemContainer, "NotDragging", true); } }