From 807a50cbe9aa48c6becc7e88c74792a443c73605 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Mon, 23 Oct 2023 21:40:22 +0200 Subject: [PATCH] Fix #3065: Hide watermark/help text of SearchBox, if contents are changed programmatically without setting the focus to the text box first. --- ILSpy/Controls/SearchBox.cs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/ILSpy/Controls/SearchBox.cs b/ILSpy/Controls/SearchBox.cs index b36640e1c5..4795bbe11b 100644 --- a/ILSpy/Controls/SearchBox.cs +++ b/ILSpy/Controls/SearchBox.cs @@ -99,6 +99,15 @@ protected override void OnTextChanged(TextChangedEventArgs e) timer.Stop(); timer.Interval = this.UpdateDelay; timer.Start(); + + UpdateWatermarkLabel(); + } + + private void UpdateWatermarkLabel() + { + Label wl = (Label)GetTemplateChild("WatermarkLabel"); + if (wl != null) + wl.Visibility = HasText ? Visibility.Hidden : Visibility.Visible; } void timer_Tick(object sender, EventArgs e) @@ -114,25 +123,13 @@ void timer_Tick(object sender, EventArgs e) protected override void OnLostFocus(RoutedEventArgs e) { - if (!HasText) - { - Label wl = (Label)GetTemplateChild("WatermarkLabel"); - if (wl != null) - wl.Visibility = Visibility.Visible; - } - + UpdateWatermarkLabel(); base.OnLostFocus(e); } protected override void OnGotFocus(RoutedEventArgs e) { - if (!HasText) - { - Label wl = (Label)GetTemplateChild("WatermarkLabel"); - if (wl != null) - wl.Visibility = Visibility.Hidden; - } - + UpdateWatermarkLabel(); base.OnGotFocus(e); }