Skip to content

Commit

Permalink
fix: PlaceholderText may not display promptly under certain circumsta…
Browse files Browse the repository at this point in the history
…nces (#1115)
  • Loading branch information
textGamex authored Jun 8, 2024
1 parent 00a4c0c commit 150e05d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Wpf.Ui/Controls/TextBox/TextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,16 @@ public class TextBox : System.Windows.Controls.TextBox
nameof(PlaceholderEnabled),
typeof(bool),
typeof(TextBox),
new PropertyMetadata(true)
new PropertyMetadata(true, OnPlaceholderEnabledChanged)
);

/// <summary>Identifies the <see cref="CurrentPlaceholderEnabled"/> dependency property.</summary>
public static readonly DependencyProperty CurrentPlaceholderEnabledProperty = DependencyProperty.Register(
nameof(CurrentPlaceholderEnabled),
typeof(bool),
typeof(TextBox),
new PropertyMetadata(true));
new PropertyMetadata(true)
);

/// <summary>Identifies the <see cref="ClearButtonEnabled"/> dependency property.</summary>
public static readonly DependencyProperty ClearButtonEnabledProperty = DependencyProperty.Register(
Expand Down Expand Up @@ -197,7 +198,7 @@ protected void SetPlaceholderTextVisibility()
SetCurrentValue(CurrentPlaceholderEnabledProperty, true);
}
}
else
else if (CurrentPlaceholderEnabled)
{
SetCurrentValue(CurrentPlaceholderEnabledProperty, false);
}
Expand Down Expand Up @@ -263,4 +264,19 @@ protected virtual void OnTemplateButtonClick(string? parameter)

OnClearButtonClick();
}

private static void OnPlaceholderEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is not TextBox control)
{
return;
}

control.OnPlaceholderEnabledChanged();
}

protected virtual void OnPlaceholderEnabledChanged()
{
SetPlaceholderTextVisibility();
}
}

0 comments on commit 150e05d

Please sign in to comment.