mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-22 17:36:36 +08:00
block
This commit is contained in:
@@ -26,7 +26,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
|
||||
}
|
||||
|
||||
public class BlockBorder : Border
|
||||
public class BlockGrid : Grid
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
FirstPoint = null;
|
||||
if (Info?.Children?.Count > 0)
|
||||
{
|
||||
var borders = VisualHelper.FindVisualChildren<BlockBorder>(this);
|
||||
var borders = VisualHelper.FindVisualChildren<BlockGrid>(this);
|
||||
foreach (var border in borders)
|
||||
{
|
||||
var itemsContainers = VisualHelper.TryFindParent<BlockItemsContainer>(border);
|
||||
|
||||
@@ -7,17 +7,59 @@
|
||||
xmlns:dd="clr-namespace:AIStudio.Wpf.DiagramDesigner"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<ItemsControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<ControlTemplate x:Key="BlockConnectorDecoratorTemplate"
|
||||
TargetType="{x:Type Control}">
|
||||
<Grid Margin="{Binding ConnectorMargin}">
|
||||
<dd:BlockConnector
|
||||
Content="{Binding LeftConnector}"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="Left"
|
||||
VerticalAlignment="Stretch"
|
||||
HorizontalAlignment="Left"/>
|
||||
<dd:BlockConnector
|
||||
Content="{Binding TopConnector}"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="Top"
|
||||
VerticalAlignment="Top"
|
||||
HorizontalAlignment="Stretch"/>
|
||||
<dd:BlockConnector
|
||||
Content="{Binding RightConnector}"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="Right"
|
||||
VerticalAlignment="Stretch"
|
||||
HorizontalAlignment="Right"/>
|
||||
<dd:BlockConnector
|
||||
Content="{Binding BottomConnector}"
|
||||
SnapsToDevicePixels="True"
|
||||
Orientation="Bottom"
|
||||
VerticalAlignment="Bottom"
|
||||
HorizontalAlignment="Stretch"/>
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</ResourceDictionary>
|
||||
</ItemsControl.Resources>
|
||||
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="{x:Type ListBoxItem}">
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ListBoxItem}">
|
||||
<dd:BlockBorder
|
||||
<dd:BlockGrid
|
||||
dd:WidthAndHeightProps.Active="True"
|
||||
dd:WidthAndHeightProps.BoundActualWidth="{Binding ActualItemWidth,Mode=OneWayToSource}"
|
||||
dd:WidthAndHeightProps.BoundActualHeight="{Binding ActualItemHeight,Mode=OneWayToSource}">
|
||||
<ContentControl Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
|
||||
</dd:BlockBorder>
|
||||
<!-- PART_ConnectorDecorator -->
|
||||
<Control x:Name="PART_ConnectorDecorator" Template="{StaticResource BlockConnectorDecoratorTemplate}"/>
|
||||
</dd:BlockGrid>
|
||||
|
||||
<ControlTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding Connectors.Count}" Value="0">
|
||||
<Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Collapsed" />
|
||||
</DataTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using AIStudio.Wpf.DiagramDesigner.Geometrys;
|
||||
using AIStudio.Wpf.DiagramDesigner.Models;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
@@ -52,6 +53,29 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
}
|
||||
}
|
||||
|
||||
public override PointBase Position
|
||||
{
|
||||
get
|
||||
{
|
||||
if (DataItem?.ParentContainer == null)
|
||||
{
|
||||
return PointHelper.GetPointForConnector(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PointHelper.GetPointForConnector(this);//Todo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override PointBase MiddlePosition
|
||||
{
|
||||
get
|
||||
{
|
||||
return PointHelper.GetPointForConnector(this, true);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool CanAttachTo(ConnectorInfoBase port)
|
||||
{
|
||||
if (port is BlockConnectorInfo blockConnectorInfo)
|
||||
|
||||
@@ -137,14 +137,28 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
var offset = GetOffSetFunc?.Invoke() ?? new Point(0, 0);
|
||||
|
||||
var containBound = new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y, GetItemWidth(), GetItemHeight());
|
||||
//foreach(var child in Children)
|
||||
//{
|
||||
// var bound = new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y, child.GetItemWidth(), child.GetItemHeight());
|
||||
//}
|
||||
|
||||
return containBound;
|
||||
}
|
||||
|
||||
public List<RectangleBase> GetChildrenBounds()
|
||||
{
|
||||
List<RectangleBase> bounds = new List<RectangleBase>();
|
||||
var offset = GetOffSetFunc?.Invoke() ?? new Point(0, 0);
|
||||
|
||||
var containBound = new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y, GetItemWidth(), GetItemHeight());
|
||||
double height = 0;
|
||||
foreach (var child in Children)
|
||||
{
|
||||
var bound = new RectangleBase(DataItem.Left + offset.X, DataItem.Top + offset.Y + height, child.GetItemWidth(), child.GetItemHeight());
|
||||
bounds.Add(bound);
|
||||
|
||||
height += child.GetItemHeight();
|
||||
}
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
public BlockDesignerItemViewModel DataItem
|
||||
{
|
||||
get
|
||||
|
||||
@@ -126,13 +126,15 @@ namespace AIStudio.Wpf.DiagramDesigner
|
||||
innerport.DataItem.ShowConnectors = true;
|
||||
if (innerport.CanAttachTo(blockDesignerItemTempLink.Items.FirstOrDefault()) == true)
|
||||
{
|
||||
if (innerport.OnlyOneChild)
|
||||
if (innerport.OnlyOneChild || innerport.Children.Count == 0)
|
||||
{
|
||||
innerport.BeAttachTo = true;
|
||||
return innerport;
|
||||
}
|
||||
else
|
||||
{
|
||||
var childrenbounds = container.GetChildrenBounds();
|
||||
|
||||
innerport.BeAttachTo = true;
|
||||
return innerport;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user