diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml
index cae3d20169..55231363d2 100644
--- a/samples/ControlCatalog/Pages/TextBoxPage.xaml
+++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml
@@ -36,7 +36,7 @@
-
+
diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs
index 6e534bbb2a..ef33ac19f6 100644
--- a/src/Avalonia.Controls/Presenters/TextPresenter.cs
+++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs
@@ -14,6 +14,9 @@ namespace Avalonia.Controls.Presenters
o => o.CaretIndex,
(o, v) => o.CaretIndex = v);
+ public static readonly StyledProperty ShowPasswordCharProperty =
+ AvaloniaProperty.Register(nameof(ShowPasswordChar), true);
+
public static readonly StyledProperty PasswordCharProperty =
AvaloniaProperty.Register(nameof(PasswordChar));
@@ -75,7 +78,7 @@ namespace Avalonia.Controls.Presenters
static TextPresenter()
{
AffectsRender(SelectionBrushProperty);
- AffectsMeasure(TextProperty, PasswordCharProperty,
+ AffectsMeasure(TextProperty, PasswordCharProperty, ShowPasswordCharProperty,
TextAlignmentProperty, TextWrappingProperty, TextBlock.FontSizeProperty,
TextBlock.FontStyleProperty, TextBlock.FontWeightProperty, TextBlock.FontFamilyProperty);
@@ -84,7 +87,7 @@ namespace Avalonia.Controls.Presenters
TextBlock.FontSizeProperty.Changed, TextBlock.FontStyleProperty.Changed,
TextBlock.FontWeightProperty.Changed, TextBlock.FontFamilyProperty.Changed,
SelectionStartProperty.Changed, SelectionEndProperty.Changed,
- SelectionForegroundBrushProperty.Changed, PasswordCharProperty.Changed
+ SelectionForegroundBrushProperty.Changed, PasswordCharProperty.Changed, ShowPasswordCharProperty.Changed
).AddClassHandler((x, _) => x.InvalidateFormattedText());
CaretIndexProperty.Changed.AddClassHandler((x, e) => x.CaretIndexChanged((int)e.NewValue));
@@ -210,6 +213,12 @@ namespace Avalonia.Controls.Presenters
set => SetValue(PasswordCharProperty, value);
}
+ public bool ShowPasswordChar
+ {
+ get => GetValue(ShowPasswordCharProperty);
+ set => SetValue(ShowPasswordCharProperty, value);
+ }
+
public IBrush SelectionBrush
{
get => GetValue(SelectionBrushProperty);
@@ -426,7 +435,7 @@ namespace Avalonia.Controls.Presenters
var text = Text;
- if (PasswordChar != default(char))
+ if (PasswordChar != default(char) && ShowPasswordChar)
{
result = CreateFormattedTextInternal(_constraint, new string(PasswordChar, text?.Length ?? 0));
}
diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs
index 23728d7997..08e4e923f5 100644
--- a/src/Avalonia.Controls/TextBox.cs
+++ b/src/Avalonia.Controls/TextBox.cs
@@ -101,8 +101,8 @@ namespace Avalonia.Controls
public static readonly StyledProperty