From 1991f529806929f1d27634ec0bc7a302dd918372 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Tue, 22 Oct 2024 22:18:55 +0800 Subject: [PATCH] feat: simplify code with switch. --- .../Controls/DateTimePicker/DatePicker.cs | 34 ++++++++--------- .../DateTimePicker/DateRangePicker.cs | 38 +++++++++---------- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/Ursa/Controls/DateTimePicker/DatePicker.cs b/src/Ursa/Controls/DateTimePicker/DatePicker.cs index 80bb2a3..445ce53 100644 --- a/src/Ursa/Controls/DateTimePicker/DatePicker.cs +++ b/src/Ursa/Controls/DateTimePicker/DatePicker.cs @@ -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() diff --git a/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs b/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs index 69734a7..157a2f4 100644 --- a/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs +++ b/src/Ursa/Controls/DateTimePicker/DateRangePicker.cs @@ -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); } } \ No newline at end of file