From 32a34117e75f735245797390a2308987b9aceab3 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 1 Aug 2020 10:19:06 +0800 Subject: [PATCH] prototype --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 20 ++++++++----- src/Avalonia.Controls/TextBox.cs | 28 +++++++++++++++++-- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index 348a285f44..d6fc234f17 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -4,21 +4,26 @@ + + TextBox @@ -31,7 +36,8 @@ - + + @@ -42,8 +48,8 @@ - - + + resm fonts diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 0a785c3b36..23728d7997 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -101,6 +101,9 @@ namespace Avalonia.Controls public static readonly StyledProperty InnerRightContentProperty = AvaloniaProperty.Register(nameof(InnerRightContent)); + public static readonly StyledProperty ShowPasswordProperty = + AvaloniaProperty.Register(nameof(ShowPassword)); + struct UndoRedoState : IEquatable { public string Text { get; } @@ -129,6 +132,10 @@ namespace Avalonia.Controls static TextBox() { FocusableProperty.OverrideDefaultValue(typeof(TextBox), true); + ShowPasswordProperty.Changed.Subscribe((x)=> + { + + }); } public TextBox() @@ -291,7 +298,7 @@ namespace Avalonia.Controls else { HandleTextInput(value); - } + } _undoRedoHelper.Snapshot(); } } @@ -344,6 +351,16 @@ namespace Avalonia.Controls set { SetValue(InnerRightContentProperty, value); } } + public bool ShowPassword + { + get { return GetValue(ShowPasswordProperty); } + set + { + + SetValue(ShowPasswordProperty, value); + } + } + public TextWrapping TextWrapping { get { return GetValue(TextWrappingProperty); } @@ -774,7 +791,7 @@ namespace Avalonia.Controls // if it did not, we change the selection to where the user clicked var firstSelection = Math.Min(SelectionStart, SelectionEnd); var lastSelection = Math.Max(SelectionStart, SelectionEnd); - var didClickInSelection = SelectionStart != SelectionEnd && + var didClickInSelection = SelectionStart != SelectionEnd && caretIndex >= firstSelection && caretIndex <= lastSelection; if (!didClickInSelection) { @@ -821,6 +838,11 @@ namespace Avalonia.Controls } } + public void Clear() + { + Text = string.Empty; + } + private int DeleteCharacter(int index) { var start = index + 1; @@ -1086,7 +1108,7 @@ namespace Avalonia.Controls SelectionEnd = CaretIndex; } - private bool IsPasswordBox => PasswordChar != default(char); + private bool IsPasswordBox => ShowPassword && PasswordChar != default(char); UndoRedoState UndoRedoHelper.IUndoRedoHost.UndoRedoState {