diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockDesignerItemViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockDesignerItemViewModel.cs index c203747..b2be125 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockDesignerItemViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/DefaultViewModel/BlockDesignerItemViewModel.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using AIStudio.Wpf.DiagramDesigner.Models; +using static System.Net.Mime.MediaTypeNames; namespace AIStudio.Wpf.DiagramDesigner { @@ -42,17 +43,36 @@ namespace AIStudio.Wpf.DiagramDesigner public void AddNext(BlockDesignerItemViewModel next) { - this.ParentId = new Guid(); - this.Parent = null; + if (this.Next == next) + { + AlignNext(next); + return; + } + RemoveNext(); + next.Left = this.Left; next.Top = this.Top + this.GetItemHeight(); next.ParentId = this.Id; next.Parent = this; this.Next = next; - //if (oldnext != null) - //{ - // next.AddNext(oldnext); - //} + if (next.Next != null) + { + next.AlignNext(next.Next); + } + } + + public void AlignNext(BlockDesignerItemViewModel next) + { + if (next != null && this.Next == next) + { + next.Left = this.Left; + next.Top = this.Top + this.GetItemHeight(); + if (next.Next != null) + { + next.AlignNext(next.Next); + } + return; + } } public void RemoveNext() @@ -100,12 +120,16 @@ namespace AIStudio.Wpf.DiagramDesigner { child.RemoveFromSelection(); this.AddToSelection(true, false); + + AlignNext(this.Next); } public virtual void RemoveChild(BlockDesignerItemViewModel child) { this.RemoveFromSelection(); child.AddToSelection(true, false); + + AlignNext(this.Next); } public ObservableCollection Contains