小优化

This commit is contained in:
艾竹
2023-02-03 22:36:08 +08:00
parent bd90d55ca8
commit da8cf08051
2 changed files with 11 additions and 4 deletions

View File

@@ -162,7 +162,7 @@
</DataTemplate.Triggers>
</DataTemplate>
<DataTemplate DataType="{x:Type model:MultipleDesignerItemToolBoxData}">
<Grid ToolTip="{Binding Description}">
<Grid Width="{Binding Width}" Height="{Binding Height}" ToolTip="{Binding Description}">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="删除" Command="{StaticResource DeleteItemCommandReference}" CommandParameter="{Binding .}"/>
@@ -173,7 +173,7 @@
StrokeDashArray="2"
Fill="Transparent"
SnapsToDevicePixels="true"/>
<Viewbox Stretch="Uniform" Width="{Binding Width}" Height="{Binding Height}">
<Viewbox Stretch="Uniform" Margin="2">
<ItemsControl ItemsSource="{Binding SelectableDesignerItemViewModels}"
Width="{Binding CanvasWidth}"
Height="{Binding CanvasHeight}">

View File

@@ -572,10 +572,17 @@ namespace AIStudio.Wpf.DiagramDesigner
if (dragObject.DesignerItem is SerializableObject serializableObject)
{
var designerItems = serializableObject.ToObject();
var minleft = designerItems.OfType<DesignerItemViewModelBase>().Min(p => p.Left);
var mintop = designerItems.OfType<DesignerItemViewModelBase>().Min(p => p.Top);
var maxright = designerItems.OfType<DesignerItemViewModelBase>().Max(p => p.Left + p.ItemWidth);
var maxbottom = designerItems.OfType<DesignerItemViewModelBase>().Max(p => p.Top + p.ItemHeight);
var itemswidth = maxright - minleft;
var itemsheight = maxbottom - mintop;
foreach (var item in designerItems.OfType<DesignerItemViewModelBase>())
{
item.Left += position.X;
item.Top += position.Y;
item.Left += position.X - itemswidth / 2;
item.Top += position.Y - itemsheight / 2;
}
_viewModel.AddItemCommand.Execute(designerItems);
}