Skip to content

Commit

Permalink
Fix #3065: Hide watermark/help text of SearchBox, if contents are cha…
Browse files Browse the repository at this point in the history
…nged programmatically without setting the focus to the text box first.
  • Loading branch information
siegfriedpammer committed Oct 23, 2023
1 parent e2ed67d commit 807a50c
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions ILSpy/Controls/SearchBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down

0 comments on commit 807a50c

Please sign in to comment.