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)
{
if (e.Key == Key.Escape)
switch (e.Key)
{
SetCurrentValue(IsDropdownOpenProperty, false);
e.Handled = true;
return;
case Key.Escape:
SetCurrentValue(IsDropdownOpenProperty, false);
e.Handled = true;
return;
case Key.Down:
SetCurrentValue(IsDropdownOpenProperty, true);
e.Handled = true;
return;
case Key.Tab:
SetCurrentValue(IsDropdownOpenProperty, false);
return;
default:
base.OnKeyDown(e);
break;
}
if (e.Key == Key.Down)
{
SetCurrentValue(IsDropdownOpenProperty, true);
e.Handled = true;
return;
}
if (e.Key == Key.Tab)
{
SetCurrentValue(IsDropdownOpenProperty, false);
return;
}
base.OnKeyDown(e);
}
public void Clear()

View File

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