2021-07-23 09:42:22 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
using System.Windows.Navigation;
|
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
|
2022-10-28 22:45:39 +08:00
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Interaction logic for ConnectorContainer.xaml
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class ConnectorContainer : ItemsControl
|
|
|
|
|
|
{
|
|
|
|
|
|
private Canvas rootCanvas;
|
|
|
|
|
|
public ConnectorContainer()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
((INotifyCollectionChanged)Items).CollectionChanged += ConnectorContainer_CollectionChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectorContainer_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (e.Action == NotifyCollectionChangedAction.Add)
|
|
|
|
|
|
{
|
2023-02-20 23:01:26 +08:00
|
|
|
|
foreach (var item in e.NewItems)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
|
|
|
|
|
FullyCreatedConnectorInfo vm = item as FullyCreatedConnectorInfo;
|
|
|
|
|
|
var connector = ItemContainerGenerator.ContainerFromItem(item) as ContentPresenter;
|
2023-02-20 23:01:26 +08:00
|
|
|
|
if (connector != null)
|
|
|
|
|
|
{
|
2025-02-03 15:22:00 +08:00
|
|
|
|
vm.PropertyChanged -= Vm_PropertyChanged;
|
|
|
|
|
|
vm.PropertyChanged += Vm_PropertyChanged;
|
2023-06-11 23:58:22 +08:00
|
|
|
|
Canvas.SetLeft(connector, vm.DataItem.GetItemWidth() * vm.XRatio - vm.ConnectorWidth / 2);
|
|
|
|
|
|
Canvas.SetTop(connector, vm.DataItem.GetItemHeight() * vm.YRatio - vm.ConnectorHeight / 2);
|
2023-02-20 23:01:26 +08:00
|
|
|
|
}
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
2023-02-20 23:01:26 +08:00
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
2023-02-20 23:01:26 +08:00
|
|
|
|
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ConnectorContainer_SizeChanged(object sender, SizeChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
SetConnectorLocation();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void rootCanvas_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
rootCanvas = sender as Canvas;
|
|
|
|
|
|
SetConnectorLocation();
|
|
|
|
|
|
SizeChanged += ConnectorContainer_SizeChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetConnectorLocation()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var connector in rootCanvas.Children.OfType<ContentPresenter>())
|
|
|
|
|
|
{
|
|
|
|
|
|
var vm = connector.DataContext as FullyCreatedConnectorInfo;
|
|
|
|
|
|
if (vm != null)
|
2025-02-03 15:22:00 +08:00
|
|
|
|
{
|
|
|
|
|
|
vm.PropertyChanged -= Vm_PropertyChanged;
|
|
|
|
|
|
vm.PropertyChanged += Vm_PropertyChanged;
|
|
|
|
|
|
Canvas.SetLeft(connector, vm.DataItem.GetItemWidth() * vm.XRatio - vm.ConnectorWidth / 2);
|
|
|
|
|
|
Canvas.SetTop(connector, vm.DataItem.GetItemHeight() * vm.YRatio - vm.ConnectorHeight / 2);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Vm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (sender is FullyCreatedConnectorInfo vm)
|
|
|
|
|
|
{
|
|
|
|
|
|
var connector = ItemContainerGenerator.ContainerFromItem(vm) as ContentPresenter;
|
|
|
|
|
|
if (connector != null)
|
2021-07-23 09:42:22 +08:00
|
|
|
|
{
|
2025-01-19 11:02:03 +08:00
|
|
|
|
Canvas.SetLeft(connector, vm.DataItem.GetItemWidth() * vm.XRatio - vm.ConnectorWidth / 2);
|
|
|
|
|
|
Canvas.SetTop(connector, vm.DataItem.GetItemHeight() * vm.YRatio - vm.ConnectorHeight / 2);
|
2021-07-23 09:42:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|