feat: simplify code with switch.

This commit is contained in:
rabbitism
2024-10-22 22:18:55 +08:00
parent dd3cebe66f
commit 1991f52980
2 changed files with 33 additions and 39 deletions

View File

@@ -190,27 +190,23 @@ public class DatePicker: DatePickerBase, IClearControl
protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyDown(KeyEventArgs e)
{ {
if (e.Key == Key.Escape) switch (e.Key)
{ {
case Key.Escape:
SetCurrentValue(IsDropdownOpenProperty, false); SetCurrentValue(IsDropdownOpenProperty, false);
e.Handled = true; e.Handled = true;
return; return;
} case Key.Down:
if (e.Key == Key.Down)
{
SetCurrentValue(IsDropdownOpenProperty, true); SetCurrentValue(IsDropdownOpenProperty, true);
e.Handled = true; e.Handled = true;
return; return;
} case Key.Tab:
if (e.Key == Key.Tab)
{
SetCurrentValue(IsDropdownOpenProperty, false); SetCurrentValue(IsDropdownOpenProperty, false);
return; return;
} default:
base.OnKeyDown(e); base.OnKeyDown(e);
break;
}
} }
public void Clear() public void Clear()

View File

@@ -434,21 +434,17 @@ public class DateRangePicker : DatePickerBase, IClearControl
protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyDown(KeyEventArgs e)
{ {
if (e.Key == Key.Escape) switch (e.Key)
{ {
case Key.Escape:
SetCurrentValue(IsDropdownOpenProperty, false); SetCurrentValue(IsDropdownOpenProperty, false);
e.Handled = true; e.Handled = true;
return; return;
} case Key.Down:
if (e.Key == Key.Down)
{
SetCurrentValue(IsDropdownOpenProperty, true); SetCurrentValue(IsDropdownOpenProperty, true);
e.Handled = true; e.Handled = true;
return; return;
} case Key.Tab:
if (e.Key == Key.Tab)
{ {
if(_endTextBox?.IsFocused == true) if(_endTextBox?.IsFocused == true)
{ {
@@ -456,8 +452,10 @@ public class DateRangePicker : DatePickerBase, IClearControl
} }
return; return;
} }
default:
base.OnKeyDown(e); base.OnKeyDown(e);
break;
}
} }
} }