Files
aistudio-wpf-diagram/AIStudio.Wpf.DiagramDesigner/Controls/Connector.cs

51 lines
1.3 KiB
C#
Raw Normal View History

2021-07-23 09:42:22 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
2022-10-28 22:45:39 +08:00
namespace AIStudio.Wpf.DiagramDesigner
2021-07-23 09:42:22 +08:00
{
2023-01-29 22:54:06 +08:00
public class Connector : ContentControl
2021-07-23 09:42:22 +08:00
{
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
DesignerCanvas canvas = GetDesignerCanvas(this);
if (canvas != null)
{
canvas.SourceConnector = this;
}
}
public ConnectorOrientation Orientation { get; set; }
// iterate through visual tree to get parent DesignerCanvas
private DesignerCanvas GetDesignerCanvas(DependencyObject element)
{
while (element != null && !(element is DesignerCanvas))
element = VisualTreeHelper.GetParent(element);
return element as DesignerCanvas;
}
2023-05-03 09:59:46 +08:00
public ConnectorInfoBase Info
2023-01-29 22:54:06 +08:00
{
get
{
2023-05-03 09:59:46 +08:00
if (Content is ConnectorInfoBase connectorInfo)
2023-01-29 22:54:06 +08:00
return connectorInfo;
2023-05-03 09:59:46 +08:00
return this.DataContext as ConnectorInfoBase;
2023-01-29 22:54:06 +08:00
}
}
2021-07-23 09:42:22 +08:00
}
}