Skip to content

fix: PlaceholderText may not display promptly under certain circumstances #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading