diff --git a/NodifyM.Avalonia.Example/MainWindow.axaml b/NodifyM.Avalonia.Example/MainWindow.axaml
index a2cce0b..e25253a 100644
--- a/NodifyM.Avalonia.Example/MainWindow.axaml
+++ b/NodifyM.Avalonia.Example/MainWindow.axaml
@@ -112,7 +112,6 @@
diff --git a/NodifyM.Avalonia/Controls/BaseNode.axaml.cs b/NodifyM.Avalonia/Controls/BaseNode.axaml.cs
index 18a0784..939f9b3 100644
--- a/NodifyM.Avalonia/Controls/BaseNode.axaml.cs
+++ b/NodifyM.Avalonia/Controls/BaseNode.axaml.cs
@@ -13,8 +13,15 @@ namespace NodifyM.Avalonia.Controls;
public class BaseNode : ContentControl
{
public static readonly AvaloniaProperty LocationProperty =
- AvaloniaProperty.Register(nameof(Location));
- public static readonly RoutedEvent LocationChangedEvent = RoutedEvent.Register(nameof(LocationChanged), RoutingStrategies.Bubble, typeof(Node));
+ AvaloniaProperty.Register(nameof(Location));
+ public static readonly RoutedEvent LocationChangedEvent = RoutedEvent.Register(nameof(LocationChanged), RoutingStrategies.Bubble, typeof(BaseNode));
+ public static readonly AvaloniaProperty IsSelectedProperty =
+ AvaloniaProperty.Register(nameof(IsSelected));
+ public bool IsSelected
+ {
+ get => (bool)GetValue(IsSelectedProperty);
+ set => SetValue(IsSelectedProperty, value);
+ }
public event EventHandler LocationChanged
{
add => AddHandler(LocationChangedEvent, value);
@@ -63,9 +70,14 @@ private void OnPointerPressed(object sender, PointerPressedEventArgs e)
foreach (var visual in parent)
{
visual.ZIndex = 0;
-
+ var first = visual.GetVisualChildren().First();
+ if (first is BaseNode baseNode)
+ {
+ baseNode.IsSelected = false;
+ }
}
visualParent.ZIndex = 1;
+ this.IsSelected = true;
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
// 启动拖动
isDragging = true;
@@ -88,7 +100,7 @@ private void OnPointerReleased(object sender, PointerReleasedEventArgs e)
isDragging = false;
e.Handled = true;
// 停止计时器
-
+ _editor.ClearAlignmentLine();
// var currentPoint = e.GetCurrentPoint(this);
// Debug.WriteLine($"停止拖动坐标X:{OffsetX} Y:{OffsetY}");
@@ -105,7 +117,14 @@ private void OnPointerMoved(object sender, PointerEventArgs e)
var currentMousePosition = e.GetPosition(((Visual)this.GetLogicalParent()).GetVisualParent());
var offset = currentMousePosition - lastMousePosition;
- ((BaseNodeViewModel)DataContext).Location = e.KeyModifiers.HasFlag(KeyModifiers.Shift) ? new Point((offset.X + _startOffsetX), offset.Y + _startOffsetY) : _editor.TryAlignNode(this,new Point((offset.X + _startOffsetX), offset.Y + _startOffsetY));
+ if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
+ {
+ _editor.ClearAlignmentLine();
+ ((BaseNodeViewModel)DataContext).Location = new Point((offset.X + _startOffsetX), offset.Y + _startOffsetY);
+ }
+ else
+ ((BaseNodeViewModel)DataContext).Location = _editor.TryAlignNode(this,
+ new Point((offset.X + _startOffsetX), offset.Y + _startOffsetY));
RaiseEvent(new RoutedEventArgs(LocationChangedEvent,this));
}
diff --git a/NodifyM.Avalonia/Controls/KnotNode.axaml b/NodifyM.Avalonia/Controls/KnotNode.axaml
index 076b024..a22b753 100644
--- a/NodifyM.Avalonia/Controls/KnotNode.axaml
+++ b/NodifyM.Avalonia/Controls/KnotNode.axaml
@@ -35,7 +35,7 @@
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
CornerRadius="3">
-
diff --git a/NodifyM.Avalonia/Controls/Node.axaml b/NodifyM.Avalonia/Controls/Node.axaml
index da10b8a..26625d6 100644
--- a/NodifyM.Avalonia/Controls/Node.axaml
+++ b/NodifyM.Avalonia/Controls/Node.axaml
@@ -11,6 +11,7 @@
diff --git a/NodifyM.Avalonia/Controls/Node.axaml.cs b/NodifyM.Avalonia/Controls/Node.axaml.cs
index 64a9bb6..b25e08c 100644
--- a/NodifyM.Avalonia/Controls/Node.axaml.cs
+++ b/NodifyM.Avalonia/Controls/Node.axaml.cs
@@ -54,13 +54,7 @@ public class Node : BaseNode
public static readonly AvaloniaProperty OutputProperty =
AvaloniaProperty.Register(nameof(Output));
- public static readonly AvaloniaProperty IsSelectedProperty =
- AvaloniaProperty.Register(nameof(IsSelected));
- public bool IsSelected
- {
- get => (bool)GetValue(IsSelectedProperty);
- set => SetValue(IsSelectedProperty, value);
- }
+
public Brush ContentBrush
{
diff --git a/NodifyM.Avalonia/Controls/NodifyEditor.axaml b/NodifyM.Avalonia/Controls/NodifyEditor.axaml
index cf22391..8e9f127 100644
--- a/NodifyM.Avalonia/Controls/NodifyEditor.axaml
+++ b/NodifyM.Avalonia/Controls/NodifyEditor.axaml
@@ -30,8 +30,8 @@
-