public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, MouseEventArgs e, Action <DesignItem> drawItemCallback) { var createdItem = CreateItem(panel.Context, createItemType); var startPoint = e.GetPosition(clickedOn.View); var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn, new DesignItem[] { createdItem }, new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) }, PlacementType.AddItem); if (operation != null) { createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem }); operation.Commit(); } createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black); createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); if (drawItemCallback != null) { drawItemCallback(createdItem); } var lineHandler = createdItem.Extensions.OfType <LineHandlerExtension>().First(); lineHandler.DragListener.ExternalStart(); new DrawLineMouseGesture(lineHandler, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs)e); }
public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, System.Windows.Input.MouseEventArgs e) { var createdItem = CreateItem(panel.Context, createItemType); var startPoint = e.GetPosition(clickedOn.View); var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn, new DesignItem[] { createdItem }, new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) }, PlacementType.AddItem); if (operation != null) { createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem }); operation.Commit(); } createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black); createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); if (createItemType == typeof(Polyline)) { createdItem.Properties[Polyline.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0, 0))); } else { createdItem.Properties[Polygon.PointsProperty].CollectionElements.Add(createdItem.Services.Component.RegisterComponentForDesigner(new Point(0, 0))); } new DrawPolylineMouseGesture(createdItem, clickedOn.View, changeGroup).Start(panel, (MouseButtonEventArgs)e); }
public void StartDrawItem(DesignItem clickedOn, Type createItemType, IDesignPanel panel, MouseEventArgs e, Action <DesignItem> drawItemCallback) { var createdItem = CreateItem(panel.Context, createItemType); var startPoint = e.GetPosition(clickedOn.View); var operation = PlacementOperation.TryStartInsertNewComponents(clickedOn, new DesignItem[] { createdItem }, new Rect[] { new Rect(startPoint.X, startPoint.Y, double.NaN, double.NaN) }, PlacementType.AddItem); if (operation != null) { createdItem.Services.Selection.SetSelectedComponents(new DesignItem[] { createdItem }); operation.Commit(); } createdItem.Properties[Shape.StrokeProperty].SetValue(Brushes.Black); createdItem.Properties[Shape.StrokeThicknessProperty].SetValue(2d); createdItem.Properties[Shape.StretchProperty].SetValue(Stretch.None); if (drawItemCallback != null) { drawItemCallback(createdItem); } var figure = new PathFigure(); var geometry = new PathGeometry(); var geometryDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(geometry); var figureDesignItem = createdItem.Services.Component.RegisterComponentForDesigner(figure); createdItem.Properties[Path.DataProperty].SetValue(geometry); //geometryDesignItem.Properties[PathGeometry.FiguresProperty].CollectionElements.Add(figureDesignItem); figureDesignItem.Properties[PathFigure.StartPointProperty].SetValue(new Point(0, 0)); new DrawPathMouseGesture(figure, createdItem, clickedOn.View, changeGroup, this.ExtendedItem.GetCompleteAppliedTransformationToView()).Start(panel, (MouseButtonEventArgs)e); }
/// <summary> /// Adds Items under a parent given that the content property is collection and can add types of <paramref name="pastedItems"/> /// </summary> /// <param name="parent">The Parent element</param> /// <param name="pastedItems">The list of elements to be added</param> void AddInParent(DesignItem parent,IList<DesignItem> pastedItems) { IEnumerable<Rect> rects = pastedItems.Select(i => new Rect(new Point(0, 0), new Point((double)i.Properties["Width"].ValueOnInstance, (double)i.Properties["Height"].ValueOnInstance))); var operation = PlacementOperation.TryStartInsertNewComponents(parent, pastedItems, rects.ToList(), PlacementType.PasteItem); ISelectionService selection = _context.Services.Selection; selection.SetSelectedComponents(pastedItems); if(operation != null) operation.Commit(); }
protected override void OnDragStarted(MouseEventArgs e) { operation = PlacementOperation.TryStartInsertNewComponents(container, new DesignItem[] { createdItem }, new Rect[] { GetStartToEndRect(e).Round() }, PlacementType.Resize); if (operation != null) { services.Selection.SetSelectedComponents(new DesignItem[] { createdItem }); } }
private bool AddItemsWithCustomSize(DesignItem container, DesignItem[] createdItems, IList <Rect> positions) { PlacementOperation operation = null; while (operation == null && container != null) { operation = PlacementOperation.TryStartInsertNewComponents( container, createdItems, positions, PlacementType.AddItem ); if (operation != null) { break; } try { if (container.Parent != null) { var rel = container.View.TranslatePoint(new Point(0, 0), container.Parent.View); for (var index = 0; index < positions.Count; index++) { positions[index] = new Rect(new Point(positions[index].X + rel.X, positions[index].Y + rel.Y), positions[index].Size); } } } catch (Exception) { } container = container.Parent; } if (operation != null) { container.Services.Selection.SetSelectedComponents(createdItems); operation.Commit(); return(true); } else { return(false); } }
internal static bool AddItemWithCustomSize(DesignItem container, DesignItem createdItem, Point position, Size size) { 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 AddItemsWithCustomSize(DesignItem container, DesignItem[] createdItems, IList <Rect> positions) { PlacementOperation operation = PlacementOperation.TryStartInsertNewComponents( container, createdItems, positions, PlacementType.AddItem ); if (operation != null) { container.Services.Selection.SetSelectedComponents(createdItems); operation.Commit(); return(true); } else { return(false); } }
public static Tuple <DesignItem, Rect> WrapItemsNewContainer(IEnumerable <DesignItem> items, Type containerType, bool doInsert = true) { var collection = items; var _context = collection.First().Context as XamlDesignContext; var container = collection.First().Parent; if (collection.Any(x => x.Parent != container)) { return(null); } //Change Code to use the Placment Operation! var placement = container.Extensions.OfType <IPlacementBehavior>().FirstOrDefault(); if (placement == null) { return(null); } var operation = PlacementOperation.Start(items.ToList(), PlacementType.Move); var newInstance = _context.Services.ExtensionManager.CreateInstanceWithCustomInstanceFactory(containerType, null); DesignItem newPanel = _context.Services.Component.RegisterComponentForDesigner(newInstance); List <ItemPos> itemList = new List <ItemPos>(); foreach (var item in collection) { itemList.Add(GetItemPos(operation, item)); //var pos = placement.GetPosition(null, item); if (container.Component is Canvas) { item.Properties.GetAttachedProperty(Canvas.RightProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.LeftProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.TopProperty).Reset(); item.Properties.GetAttachedProperty(Canvas.BottomProperty).Reset(); } else if (container.Component is Grid) { item.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).Reset(); item.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).Reset(); item.Properties.GetProperty(FrameworkElement.MarginProperty).Reset(); } var parCol = item.ParentProperty.CollectionElements; parCol.Remove(item); } var xmin = itemList.Min(x => x.Xmin); var xmax = itemList.Max(x => x.Xmax); var ymin = itemList.Min(x => x.Ymin); var ymax = itemList.Max(x => x.Ymax); foreach (var item in itemList) { if (newPanel.Component is Canvas) { if (item.HorizontalAlignment == HorizontalAlignment.Right) { item.DesignItem.Properties.GetAttachedProperty(Canvas.RightProperty).SetValue(xmax - item.Xmax); } else { item.DesignItem.Properties.GetAttachedProperty(Canvas.LeftProperty).SetValue(item.Xmin - xmin); } if (item.VerticalAlignment == VerticalAlignment.Bottom) { item.DesignItem.Properties.GetAttachedProperty(Canvas.BottomProperty).SetValue(ymax - item.Ymax); } else { item.DesignItem.Properties.GetAttachedProperty(Canvas.TopProperty).SetValue(item.Ymin - ymin); } newPanel.ContentProperty.CollectionElements.Add(item.DesignItem); } else if (newPanel.Component is Grid) { Thickness thickness = new Thickness(0); if (item.HorizontalAlignment == HorizontalAlignment.Right) { item.DesignItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).SetValue(HorizontalAlignment.Right); thickness.Right = xmax - item.Xmax; } else { item.DesignItem.Properties.GetProperty(FrameworkElement.HorizontalAlignmentProperty).SetValue(HorizontalAlignment.Left); thickness.Left = item.Xmin - xmin; } if (item.VerticalAlignment == VerticalAlignment.Bottom) { item.DesignItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).SetValue(VerticalAlignment.Bottom); thickness.Bottom = ymax - item.Ymax; } else { item.DesignItem.Properties.GetProperty(FrameworkElement.VerticalAlignmentProperty).SetValue(VerticalAlignment.Top); thickness.Top = item.Ymin - ymin; } item.DesignItem.Properties.GetProperty(FrameworkElement.MarginProperty).SetValue(thickness); newPanel.ContentProperty.CollectionElements.Add(item.DesignItem); } else if (newPanel.Component is Viewbox) { newPanel.ContentProperty.SetValue(item.DesignItem); } } if (doInsert) { PlacementOperation operation2 = PlacementOperation.TryStartInsertNewComponents( container, new[] { newPanel }, new[] { new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round() }, PlacementType.AddItem ); operation2.Commit(); _context.Services.Selection.SetSelectedComponents(new[] { newPanel }); } operation.Commit(); return(new Tuple <DesignItem, Rect>(newPanel, new Rect(xmin, ymin, xmax - xmin, ymax - ymin).Round())); }