diff --git a/AIStudio.Wpf.DiagramDesigner.Demo/ViewModels/Customization/CustomPortViewModel.cs b/AIStudio.Wpf.DiagramDesigner.Demo/ViewModels/Customization/CustomPortViewModel.cs
new file mode 100644
index 0000000..2a82f43
--- /dev/null
+++ b/AIStudio.Wpf.DiagramDesigner.Demo/ViewModels/Customization/CustomPortViewModel.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Windows;
+
+namespace AIStudio.Wpf.DiagramDesigner.Demo.ViewModels
+{
+ class CustomPortViewModel : BaseViewModel
+ {
+ public CustomPortViewModel()
+ {
+ Title = "Simple";
+ Info = "A simple example of AIStudio.Wpf.DiagramDesigner.";
+
+ DiagramViewModel = new DiagramViewModel();
+ DiagramViewModel.PageSizeType = PageSizeType.Custom;
+ DiagramViewModel.PageSize = new Size(double.NaN, double.NaN);
+ DiagramViewModel.ColorViewModel = new ColorViewModel();
+ DiagramViewModel.ColorViewModel.FillColor.Color = System.Windows.Media.Colors.Orange;
+
+ DefaultDesignerItemViewModel node1 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 50, Top = 50, Text = "1" };
+ DiagramViewModel.DirectAddItemCommand.Execute(node1);
+
+ DefaultDesignerItemViewModel node2 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 300, Top = 300, Text = "2" };
+ DiagramViewModel.DirectAddItemCommand.Execute(node2);
+
+ DefaultDesignerItemViewModel node3 = new DefaultDesignerItemViewModel(DiagramViewModel) { Left = 300, Top = 50, Text = "3" };
+ DiagramViewModel.DirectAddItemCommand.Execute(node3);
+
+ ConnectionViewModel connector1 = new ConnectionViewModel(DiagramViewModel, node1.RightConnector, node2.LeftConnector, DrawMode.ConnectingLineSmooth, RouterMode.RouterNormal);
+ DiagramViewModel.DirectAddItemCommand.Execute(connector1);
+
+ ConnectionViewModel connector2 = new ConnectionViewModel(DiagramViewModel, node2.RightConnector, node3.RightConnector, DrawMode.ConnectingLineStraight, RouterMode.RouterOrthogonal);
+ DiagramViewModel.DirectAddItemCommand.Execute(connector2);
+
+ DiagramViewModel.ClearSelectedItemsCommand.Execute(null);
+ }
+ }
+}
diff --git a/AIStudio.Wpf.DiagramDesigner.Demo/Views/Customization/CustomPortView.xaml b/AIStudio.Wpf.DiagramDesigner.Demo/Views/Customization/CustomPortView.xaml
new file mode 100644
index 0000000..2aa7070
--- /dev/null
+++ b/AIStudio.Wpf.DiagramDesigner.Demo/Views/Customization/CustomPortView.xaml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/AIStudio.Wpf.DiagramDesigner.Demo/Views/Customization/CustomPortView.xaml.cs b/AIStudio.Wpf.DiagramDesigner.Demo/Views/Customization/CustomPortView.xaml.cs
new file mode 100644
index 0000000..7b17c2d
--- /dev/null
+++ b/AIStudio.Wpf.DiagramDesigner.Demo/Views/Customization/CustomPortView.xaml.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+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.Demo.Views
+{
+ ///
+ /// CustomPortView.xaml 的交互逻辑
+ ///
+ public partial class CustomPortView : UserControl
+ {
+ public CustomPortView()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/AIStudio.Wpf.DiagramDesigner/AIStudio.Wpf.DiagramDesigner_sezm4xxq_wpftmp.csproj b/AIStudio.Wpf.DiagramDesigner/AIStudio.Wpf.DiagramDesigner_sezm4xxq_wpftmp.csproj
new file mode 100644
index 0000000..67a15f9
--- /dev/null
+++ b/AIStudio.Wpf.DiagramDesigner/AIStudio.Wpf.DiagramDesigner_sezm4xxq_wpftmp.csproj
@@ -0,0 +1,267 @@
+
+
+ AIStudio.Wpf.DiagramDesigner
+ obj\Debug\
+ obj\
+ F:\aistudio.-wpf.-diagram\AIStudio.Wpf.DiagramDesigner\obj\
+ <_TargetAssemblyProjectName>AIStudio.Wpf.DiagramDesigner
+
+
+
+ true
+ AIStudio.Wpf.Controls
+ akwkevin
+ https://gitee.com/akwkevin
+ A.png
+
+
+ 1.0.4
+ 一个Wpf的Diagram控件基础库
+
+
+
+
+
+ True
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ PreserveNewest
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/Connector.cs b/AIStudio.Wpf.DiagramDesigner/Controls/Connector.cs
index b82b2ce..58ac648 100644
--- a/AIStudio.Wpf.DiagramDesigner/Controls/Connector.cs
+++ b/AIStudio.Wpf.DiagramDesigner/Controls/Connector.cs
@@ -9,10 +9,8 @@ using System.Windows.Media;
namespace AIStudio.Wpf.DiagramDesigner
{
- public class Connector : Control
+ public class Connector : ContentControl
{
-
-
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
@@ -34,6 +32,17 @@ namespace AIStudio.Wpf.DiagramDesigner
return element as DesignerCanvas;
}
+ public FullyCreatedConnectorInfo Info
+ {
+ get
+ {
+ if (Content is FullyCreatedConnectorInfo connectorInfo)
+ return connectorInfo;
+
+ return this.DataContext as FullyCreatedConnectorInfo;
+ }
+ }
+
}
diff --git a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs
index 4e49b05..2a7230f 100644
--- a/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs
+++ b/AIStudio.Wpf.DiagramDesigner/Controls/DesignerCanvas.cs
@@ -280,7 +280,8 @@ namespace AIStudio.Wpf.DiagramDesigner
{
sourceConnector = value;
connectorsHit.Add(sourceConnector);
- FullyCreatedConnectorInfo sourceDataItem = sourceConnector.DataContext as FullyCreatedConnectorInfo;
+
+ FullyCreatedConnectorInfo sourceDataItem = sourceConnector.Info;
Rect rectangleBounds = sourceConnector.TransformToVisual(this).TransformBounds(new Rect(sourceConnector.RenderSize));
@@ -348,10 +349,9 @@ namespace AIStudio.Wpf.DiagramDesigner
// drag operation we cache the start point
rubberbandSelectionStartPoint = e.GetPosition(this);
- IDiagramViewModel vm = (this.DataContext as IDiagramViewModel);
if (!(Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
{
- vm.ClearSelectedItemsCommand.Execute(null);
+ _viewModel.ClearSelectedItemsCommand.Execute(null);
}
e.Handled = true;
@@ -451,11 +451,11 @@ namespace AIStudio.Wpf.DiagramDesigner
if (sourceConnector != null)
{
- FullyCreatedConnectorInfo sourceDataItem = sourceConnectorInfo ?? (sourceConnector.DataContext as FullyCreatedConnectorInfo);
+ FullyCreatedConnectorInfo sourceDataItem = sourceConnectorInfo ?? (sourceConnector.Info);
if (connectorsHit.Count() == 2)
{
Connector sinkConnector = connectorsHit.Last();
- FullyCreatedConnectorInfo sinkDataItem = sinkConnector.DataContext as FullyCreatedConnectorInfo;
+ FullyCreatedConnectorInfo sinkDataItem = sinkConnector.Info;
int indexOfLastTempConnection = sinkDataItem.DataItem.Root.Items.Count - 1;
sinkDataItem.DataItem.Root.DirectRemoveItemCommand.Execute(
@@ -562,7 +562,7 @@ namespace AIStudio.Wpf.DiagramDesigner
DragObject dragObject = e.Data.GetData(typeof(DragObject)) as DragObject;
if (dragObject != null)
{
- (DataContext as IDiagramViewModel).ClearSelectedItemsCommand.Execute(null);
+ _viewModel.ClearSelectedItemsCommand.Execute(null);
Point position = e.GetPosition(this);
DesignerItemViewModelBase itemBase = null;
if (dragObject.DesignerItem != null)
@@ -589,7 +589,7 @@ namespace AIStudio.Wpf.DiagramDesigner
{
foreach (var file in files)
{
- (DataContext as IDiagramViewModel).ClearSelectedItemsCommand.Execute(null);
+ _viewModel.ClearSelectedItemsCommand.Execute(null);
Point position = e.GetPosition(this);
ImageItemViewModel itemBase = new ImageItemViewModel();
itemBase.Icon = file;
@@ -599,7 +599,7 @@ namespace AIStudio.Wpf.DiagramDesigner
itemBase.Left = Math.Max(0, position.X - itemBase.ItemWidth / 2);
itemBase.Top = Math.Max(0, position.Y - itemBase.ItemHeight / 2);
- (DataContext as IDiagramViewModel).AddItemCommand.Execute(itemBase);
+ _viewModel.AddItemCommand.Execute(itemBase);
}
}
e.Handled = true;
diff --git a/AIStudio.Wpf.DiagramDesigner/Converters/NullOrEmptyToBoolConverter.cs b/AIStudio.Wpf.DiagramDesigner/Converters/NullOrEmptyToBoolConverter.cs
new file mode 100644
index 0000000..c23d5fe
--- /dev/null
+++ b/AIStudio.Wpf.DiagramDesigner/Converters/NullOrEmptyToBoolConverter.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using System.Windows.Data;
+
+namespace AIStudio.Wpf.DiagramDesigner
+{
+ public class NullOrEmptyToBoolConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return string.IsNullOrEmpty(value?.ToString());
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return Binding.DoNothing;
+ }
+ }
+
+ public class NotNullOrEmptyToBoolConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return !string.IsNullOrEmpty(value?.ToString());
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return Binding.DoNothing;
+ }
+ }
+}
diff --git a/AIStudio.Wpf.DiagramDesigner/Themes/ConnectorItem.xaml b/AIStudio.Wpf.DiagramDesigner/Themes/ConnectorItem.xaml
index 4b9a3b4..2359ff2 100644
--- a/AIStudio.Wpf.DiagramDesigner/Themes/ConnectorItem.xaml
+++ b/AIStudio.Wpf.DiagramDesigner/Themes/ConnectorItem.xaml
@@ -3,56 +3,28 @@
xmlns:s="clr-namespace:AIStudio.Wpf.DiagramDesigner"
xmlns:c="clr-namespace:AIStudio.Wpf.DiagramDesigner.Controls">
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
@@ -538,7 +571,7 @@
-
+
@@ -547,14 +580,14 @@
-
+
-
+
@@ -583,13 +616,20 @@
+
-
+
+
+
+
+
+
+
@@ -828,7 +868,7 @@
-
+