From adae58bbf7228ed1ebbf3df5a67486a6de466904 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 10 Jul 2020 19:05:58 +0100 Subject: [PATCH] Fixed for dynamically added view. --- Terminal.Gui/Core/View.cs | 10 ++++++---- UnitTests/ViewTests.cs | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Core/View.cs b/Terminal.Gui/Core/View.cs index 24a2ca606..cba2baf75 100644 --- a/Terminal.Gui/Core/View.cs +++ b/Terminal.Gui/Core/View.cs @@ -621,13 +621,18 @@ namespace Terminal.Gui { container.ChildNeedsDisplay (); if (subviews == null) return; - foreach (var view in subviews) + foreach (var view in subviews) { + if (IsInitialized && !view.IsInitialized) { + view.BeginInit (); + view.EndInit (); + } if (view.Frame.IntersectsWith (region)) { var childRegion = Rect.Intersect (view.Frame, region); childRegion.X -= view.Frame.X; childRegion.Y -= view.Frame.Y; view.SetNeedsDisplay (childRegion); } + } } internal bool childNeedsDisplay; @@ -666,9 +671,6 @@ namespace Terminal.Gui { CanFocus = true; view.tabIndex = tabIndexes.IndexOf (view); } - if (IsInitialized) { - view.BeginInit (); - } SetNeedsLayout (); SetNeedsDisplay (); } diff --git a/UnitTests/ViewTests.cs b/UnitTests/ViewTests.cs index fec7fd00f..378d42e75 100644 --- a/UnitTests/ViewTests.cs +++ b/UnitTests/ViewTests.cs @@ -700,6 +700,9 @@ namespace Terminal.Gui { v1.Add (sv1); + while (!sv1.CanFocus) { + } + Application.Refresh (); t.Running = false; };