From da8cf0805128d6186c6ae81feca33415b683cd80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=89=BE=E7=AB=B9?= Date: Fri, 3 Feb 2023 22:36:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIStudio.Wpf.DiagramApp/Views/ToolBoxControl.xaml | 4 ++-- .../Controls/DesignerCanvas.cs | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/AIStudio.Wpf.DiagramApp/Views/ToolBoxControl.xaml b/AIStudio.Wpf.DiagramApp/Views/ToolBoxControl.xaml index 1364a67..e0de588 100644 --- a/AIStudio.Wpf.DiagramApp/Views/ToolBoxControl.xaml +++ b/AIStudio.Wpf.DiagramApp/Views/ToolBoxControl.xaml @@ -162,7 +162,7 @@ - + @@ -173,7 +173,7 @@ StrokeDashArray="2" Fill="Transparent" SnapsToDevicePixels="true"/> - + diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs index cc4482f..84771b1 100644 --- a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs +++ b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs @@ -572,10 +572,17 @@ namespace AIStudio.Wpf.DiagramDesigner if (dragObject.DesignerItem is SerializableObject serializableObject) { var designerItems = serializableObject.ToObject(); + var minleft = designerItems.OfType().Min(p => p.Left); + var mintop = designerItems.OfType().Min(p => p.Top); + var maxright = designerItems.OfType().Max(p => p.Left + p.ItemWidth); + var maxbottom = designerItems.OfType().Max(p => p.Top + p.ItemHeight); + var itemswidth = maxright - minleft; + var itemsheight = maxbottom - mintop; + foreach (var item in designerItems.OfType()) { - item.Left += position.X; - item.Top += position.Y; + item.Left += position.X - itemswidth / 2; + item.Top += position.Y - itemsheight / 2; } _viewModel.AddItemCommand.Execute(designerItems); }