fix: fix input issue taping Tab Key and remove FocusAdorner.

This commit is contained in:
Zhang Dian
2024-07-31 17:13:38 +08:00
parent ff666cafdc
commit d8f6ffbd87
2 changed files with 11 additions and 3 deletions

View File

@@ -5,14 +5,14 @@
<Design.PreviewWith>
<u:PinCode Count="4" />
</Design.PreviewWith>
<!-- Add Resources Here -->
<ControlTheme x:Key="{x:Type u:PinCodeItem}" TargetType="u:PinCodeItem">
<Setter Property="Focusable" Value="True" />
<Setter Property="Height" Value="{DynamicResource TextBoxDefaultHeight}" />
<Setter Property="Width" Value="{DynamicResource TextBoxDefaultHeight}" />
<Setter Property="CornerRadius" Value="{DynamicResource TextBoxDefaultCornerRadius}" />
<Setter Property="BorderThickness" Value="{DynamicResource TextBoxBorderThickness}" />
<Setter Property="Background" Value="{DynamicResource TextBoxDefaultBackground}"></Setter>
<Setter Property="Background" Value="{DynamicResource TextBoxDefaultBackground}" />
<Setter Property="FocusAdorner" Value="{x:Null}" />
<Setter Property="Template">
<ControlTemplate>
<Border
@@ -64,7 +64,6 @@
<ControlTheme x:Key="{x:Type u:PinCode}" TargetType="u:PinCode">
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Template">
<ControlTemplate TargetType="u:PinCode">
<DataValidationErrors>

View File

@@ -159,6 +159,15 @@ public class PinCode: TemplatedControl
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Tab && e.Source is PinCodeItem)
{
_currentIndex = MathHelpers.SafeClamp(_currentIndex, 0, Count - 1);
if (e.KeyModifiers == KeyModifiers.Shift)
_currentIndex--;
else
_currentIndex++;
_currentIndex = MathHelpers.SafeClamp(_currentIndex, 0, Count - 1);
}
base.OnKeyDown(e);
if (e.Key == Key.Back && _currentIndex >= 0)
{