private bool AddItems(DesignItem container, DesignItem[] createdItems)
        {
            var sizes = createdItems.Select(x =>
            {
                var fe = x.Component as FrameworkElement;
                if (fe != null &&
                    fe.ReadLocalValue(FrameworkElement.WidthProperty) != DependencyProperty.UnsetValue &&
                    fe.ReadLocalValue(FrameworkElement.HeightProperty) != DependencyProperty.UnsetValue)
                {
                    return(new Rect(x.Position, new Size(fe.Width, fe.Height)));
                }
                return(new Rect(x.Position, ModelTools.GetDefaultSize(x)));
            }).ToList();

            return(AddItemsWithCustomSize(container, createdItems, sizes));
        }
        internal static bool AddItemWithDefaultSize(DesignItem container, DesignItem createdItem, Point position)
        {
            var size = ModelTools.GetDefaultSize(createdItem);
            PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents(
                container,
                new DesignItem[] { createdItem },
                new Rect[] { new Rect(position, size).Round() },
                PlacementType.AddItem
                );

            if (operation != null)
            {
                container.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem });
                operation.Commit();
                return(true);
            }
            else
            {
                return(false);
            }
        }
 internal static bool AddItemWithDefaultSize(DesignItem container, DesignItem createdItem, Point position)
 {
     return(AddItemWithCustomSize(container, createdItem, position, ModelTools.GetDefaultSize(createdItem)));
 }
Exemple #4
0
 internal static bool AddItemsWithDefaultSize(DesignItem container, DesignItem[] createdItems)
 {
     return(AddItemsWithCustomSize(container, createdItems, createdItems.Select(x => new Rect(x.Position, ModelTools.GetDefaultSize(x))).ToList()));
 }