示例#1
0
        /// <summary>
        /// Starts a new placement operation that changes the placement of <paramref name="placedItems"/>.
        /// </summary>
        /// <param name="placedItems">The items to be placed.</param>
        /// <param name="type">The type of the placement.</param>
        /// <returns>A PlacementOperation object.</returns>
        /// <remarks>
        /// You MUST call either <see cref="Abort"/> or <see cref="Commit"/> on the returned PlacementOperation
        /// once you are done with it, otherwise a ChangeGroup will be left open and Undo/Redo will fail to work!
        /// </remarks>
        public static PlacementOperation Start(ICollection <DesignItem> placedItems, PlacementType type)
        {
            if (placedItems == null)
            {
                throw new ArgumentNullException("placedItems");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            DesignItem[] items = placedItems.ToArray();
            if (items.Length == 0)
            {
                throw new ArgumentException("placedItems.Length must be > 0");
            }

            PlacementOperation op = new PlacementOperation(items, type);

            try
            {
                if (op.currentContainerBehavior == null)
                {
                    throw new PlacementOperationException("Starting the operation is not supported");
                }

                op.currentContainerBehavior.BeginPlacement(op);
                foreach (PlacementInformation info in op.placedItems)
                {
                    info.OriginalBounds = op.currentContainerBehavior.GetPosition(op, info.Item);
                    info.Bounds         = info.OriginalBounds;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                op.changeGroup.Abort();
                throw;
            }
            return(op);
        }
示例#2
0
 internal PlacementInformation(DesignItem item, PlacementOperation operation)
 {
     this.item      = item;
     this.operation = operation;
 }