mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-03 07:36:35 +08:00
整理一下项目文件
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
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;
|
||||
|
||||
namespace AIStudio.Wpf.DiagramDesigner
|
||||
{
|
||||
/// <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)
|
||||
{
|
||||
foreach(var item in e.NewItems)
|
||||
{
|
||||
FullyCreatedConnectorInfo vm = item as FullyCreatedConnectorInfo;
|
||||
var connector = ItemContainerGenerator.ContainerFromItem(item) as ContentPresenter;
|
||||
|
||||
Canvas.SetLeft(connector, vm.DataItem.ItemWidth * vm.XRatio - vm.ConnectorWidth / 2);
|
||||
Canvas.SetTop(connector, vm.DataItem.ItemHeight * vm.YRatio - vm.ConnectorHeight / 2);
|
||||
}
|
||||
//SetConnectorLocation();
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Canvas.SetLeft(connector, vm.DataItem.ItemWidth * vm.XRatio - vm.ConnectorWidth / 2);
|
||||
Canvas.SetTop(connector, vm.DataItem.ItemHeight * vm.YRatio - vm.ConnectorHeight / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user