Skip to content

Commit a9072d6

Browse files
committed
winui: make SecurePasswordBox notify all changes
Update the `SecurePasswordBox` control to notify all listeners of changes to the password value. Previously we only notified on the first character typed into the box. We clone the current password, modify it, and then replace the previous instance (triggering an `INotifyPropertyChanged::PropertyChanged` event). With a binding delay, we will batch updates of multiple keystrokes rather than one at a time.
1 parent 342ba5b commit a9072d6

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/windows/Shared.UI.Windows/Controls/SecurePasswordBox.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public SecureString Password
4747
}
4848

4949
private bool updatingTextFromPasswordChange;
50+
5051
private void UpdateText()
5152
{
5253
updatingTextFromPasswordChange = true;
@@ -69,14 +70,17 @@ protected override void OnTextChanged(TextChangedEventArgs e)
6970
{
7071
if (!updatingTextFromPasswordChange)
7172
{
72-
SecureString password = Password;
73+
// Update a copy of the password SecureString so that we can trigger a changed event
74+
// for anyone listening on the actual password property.
75+
SecureString password = Password.Copy();
7376
int selectionStart = SelectionStart;
7477
foreach (TextChange change in e.Changes)
7578
{
7679
password.RemoveAt(change.Offset, change.RemovedLength);
7780
password.InsertAt(change.Offset, Text.Substring(change.Offset, change.AddedLength));
7881
}
7982
UpdateText();
83+
Password = password;
8084
SelectionStart = selectionStart;
8185
}
8286
base.OnTextChanged(e);

0 commit comments

Comments
 (0)