コード例 #1
0
        /// <summary>
        /// Move an item in the rendered layout.
        /// </summary>
        /// <param name="moveItemRequest"></param>
        public void MoveItem(MoveItemRequest moveItemRequest)
        {
            if (moveItemRequest == null)
            {
                throw new ArgumentNullException(nameof(moveItemRequest));
            }

            if (ItemsOrganiser == null)
            {
                return;
            }

            var dragablzItem = moveItemRequest.Item as DragablzItem ??
                               ItemContainerGenerator.ContainerFromItem(
                moveItemRequest.Item) as DragablzItem;
            var contextDragablzItem = moveItemRequest.Context as DragablzItem ??
                                      ItemContainerGenerator.ContainerFromItem(
                moveItemRequest.Context) as DragablzItem;

            if (dragablzItem == null)
            {
                return;
            }

            var sortedItems = DragablzItems( ).OrderBy(di => di.LogicalIndex).ToList( );

            sortedItems.Remove(dragablzItem);

            switch (moveItemRequest.AddLocationHint)
            {
            case AddLocationHint.First:
                sortedItems.Insert(0, dragablzItem);
                break;

            case AddLocationHint.Last:
                sortedItems.Add(dragablzItem);
                break;

            case AddLocationHint.Prior:
            case AddLocationHint.After:
                if (contextDragablzItem == null)
                {
                    return;
                }

                var contextIndex = sortedItems.IndexOf(contextDragablzItem);
                sortedItems.Insert(moveItemRequest.AddLocationHint == AddLocationHint.Prior ? contextIndex : contextIndex + 1, dragablzItem);

                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(AddLocationHint));
            }

            //TODO might not be too great for perf on larger lists
            var orderedEnumerable = sortedItems.OrderBy(di => sortedItems.IndexOf(di));

            ItemsOrganiser.Organise(this, new Size(ItemsPresenterWidth, ItemsPresenterHeight), orderedEnumerable);
        }
コード例 #2
0
        internal void MoveItem(MoveItemRequest moveItemRequest)
        {
            if (moveItemRequest == null) throw new ArgumentNullException("moveItemRequest");

            if (ItemsOrganiser == null) return;

            var dragablzItem = moveItemRequest.Item as DragablzItem ??
                               ItemContainerGenerator.ContainerFromItem(
                                   moveItemRequest.Item) as DragablzItem;
            var contextDragablzItem = moveItemRequest.Context as DragablzItem ??
                               ItemContainerGenerator.ContainerFromItem(
                                   moveItemRequest.Context) as DragablzItem;

            if (dragablzItem == null) return;

            var sortedItems = DragablzItems().OrderBy(di => di.LogicalIndex).ToList();
            sortedItems.Remove(dragablzItem);
                
            switch (moveItemRequest.AddLocationHint)
            {
                case AddLocationHint.First:
                    sortedItems.Insert(0, dragablzItem);                        
                    break;
                case AddLocationHint.Last:
                    sortedItems.Add(dragablzItem);
                    break;
                case AddLocationHint.Prior:
                case AddLocationHint.After:
                    if (contextDragablzItem == null)
                        return;

                    var contextIndex = sortedItems.IndexOf(contextDragablzItem);
                    sortedItems.Insert(moveItemRequest.AddLocationHint == AddLocationHint.Prior ? contextIndex : contextIndex + 1, dragablzItem);

                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }            

            //TODO might not be too great for perf on larger lists
            var orderedEnumerable = sortedItems.OrderBy(di => sortedItems.IndexOf(di));

            ItemsOrganiser.Organise(this, new Size(ItemsPresenterWidth, ItemsPresenterHeight), orderedEnumerable);
        }