/// <summary> /// Collects information about the NEW items and their NEW positions after changes were made. /// </summary> private RearrangeItemInfo[] BuildRearrangeMap2(RearrangeItemInfo[] map, int viewFirstIndex, int viewLastIndex) { RearrangeItemInfo[] map2 = new RearrangeItemInfo[this.Items.Count]; for (int i = 0; i < map2.Length; i++) { object item = this.Items[i]; // Try to find the same item in the pre-rearrange info. RearrangeItemInfo info = map.FirstOrDefault(rii => rii.ToIndex < 0 && rii.Item == item); if (info == null) { info = new RearrangeItemInfo() { Item = item, }; } info.ToIndex = i; // The precise item location is only important if it's within the view. if (viewFirstIndex <= i && i <= viewLastIndex) { ReorderListBoxItem itemContainer = (ReorderListBoxItem) this.ContainerFromIndex(i); if (itemContainer != null) { GeneralTransform itemTransform = itemContainer.TransformToVisual(this.rearrangeCanvas); // TODO: replaced all itemTransform.Transform with itemTransform.TransformPoint Point itemPoint = itemTransform.TransformPoint(new Point(0, 0)); info.ToY = itemPoint.Y; info.Height = itemContainer.RenderSize.Height; } } map2[i] = info; } return map2; }
/// <summary> /// Collects information about items and their positions before any changes are made. /// </summary> private RearrangeItemInfo[] BuildRearrangeMap(int viewFirstIndex, int viewLastIndex) { RearrangeItemInfo[] map = new RearrangeItemInfo[this.Items.Count]; for (int i = 0; i < map.Length; i++) { object item = this.Items[i]; RearrangeItemInfo info = new RearrangeItemInfo() { Item = item, FromIndex = i, }; // The precise item location is only important if it's within the view. if (viewFirstIndex <= i && i <= viewLastIndex) { ReorderListBoxItem itemContainer = (ReorderListBoxItem) this.ContainerFromIndex(i); if (itemContainer != null) { GeneralTransform itemTransform = itemContainer.TransformToVisual(this.rearrangeCanvas); Point itemPoint = itemTransform.TransformPoint(new Point(0, 0)); info.FromY = itemPoint.Y; info.Height = itemContainer.RenderSize.Height; } } map[i] = info; } return map; }