diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index be569d2e9..ba408a7b5 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -132,7 +132,7 @@ namespace Terminal.Gui { /// /// Event fired when a subview is being removed from this view. /// - public Action Removing; + public Action Removed; /// /// Event fired when the view gets focus. @@ -607,12 +607,12 @@ namespace Terminal.Gui { if (view == null || subviews == null) return; - OnRemoving (view); SetNeedsLayout (); SetNeedsDisplay (); var touched = view.Frame; subviews.Remove (view); view.container = null; + OnRemoved (view); if (subviews.Count < 1) this.CanFocus = false; @@ -958,9 +958,9 @@ namespace Terminal.Gui { /// Method invoked when a subview is being removed from this view. /// /// The subview being removed. - public virtual void OnRemoving (View view) + public virtual void OnRemoved (View view) { - view.Removing?.Invoke (this); + view.Removed?.Invoke (this); } /// diff --git a/UnitTests/ViewTests.cs b/UnitTests/ViewTests.cs index 43473921b..4adb55374 100644 --- a/UnitTests/ViewTests.cs +++ b/UnitTests/ViewTests.cs @@ -135,5 +135,26 @@ namespace Terminal.Gui { sub2.Width = Dim.Width (sub2); Assert.Throws (() => root.LayoutSubviews ()); } + + [Fact] + public void Added_Removing () + { + var v = new View (new Rect (0, 0, 10, 24)); + var t = new View (); + + v.Added += (View e) => { + Assert.True (v.SuperView == e); + }; + + v.Removed += (View e) => { + Assert.True (v.SuperView == null); + }; + + t.Add (v); + Assert.True (t.Subviews.Count == 1); + + t.Remove (v); + Assert.True (t.Subviews.Count == 0); + } } }