Skip to content
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

fix: 修复Password的Focus()函数失效的bug #1696

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 13 additions & 1 deletion src/Shared/HandyControl_Shared/Controls/Input/PasswordBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ public Brush CaretBrush

#endif

public PasswordBox() => CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) => Clear()));
public PasswordBox()
{
CommandBindings.Add(new CommandBinding(ControlCommands.Clear, (s, e) => Clear()));
CommandBindings.Add(new CommandBinding(ControlCommands.Focus, (s, e) => Focus()));
}

public System.Windows.Controls.PasswordBox ActualPasswordBox { get; set; }

Expand Down Expand Up @@ -270,6 +274,14 @@ public void Clear()
_textBox.Clear();
}

#pragma warning disable CS0108 // 成员隐藏继承的成员;缺少关键字 new
public void Focus()
#pragma warning restore CS0108 // 成员隐藏继承的成员;缺少关键字 new
{
ActualPasswordBox.Focus();
_textBox.Focus();
}

private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
{
if (!IsSafeEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,6 @@ public static class ControlCommands
public static RoutedCommand More { get; } = new(nameof(More), typeof(ControlCommands));

public static RoutedCommand Toggle { get; } = new(nameof(Toggle), typeof(ControlCommands));

public static RoutedCommand Focus { get; } = new(nameof(Focus), typeof(ControlCommands));
}