From 0e00158bafa1b41a2f7cd3b4cc3ffdd56062f573 Mon Sep 17 00:00:00 2001 From: rabbitism Date: Sat, 27 Apr 2024 15:08:57 +0800 Subject: [PATCH] feat: fix ampm auto derivation. --- src/Ursa.Themes.Semi/Controls/TimePicker.axaml | 3 +++ src/Ursa/Controls/DateTimePicker/TimePicker.cs | 3 +++ src/Ursa/Controls/DateTimePicker/TimePickerPresenter.cs | 8 ++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Ursa.Themes.Semi/Controls/TimePicker.axaml b/src/Ursa.Themes.Semi/Controls/TimePicker.axaml index 06420e3..3bef671 100644 --- a/src/Ursa.Themes.Semi/Controls/TimePicker.axaml +++ b/src/Ursa.Themes.Semi/Controls/TimePicker.axaml @@ -260,6 +260,9 @@ + diff --git a/src/Ursa/Controls/DateTimePicker/TimePicker.cs b/src/Ursa/Controls/DateTimePicker/TimePicker.cs index c4447a5..25e0ff8 100644 --- a/src/Ursa/Controls/DateTimePicker/TimePicker.cs +++ b/src/Ursa/Controls/DateTimePicker/TimePicker.cs @@ -118,6 +118,7 @@ public class TimePicker : TemplatedControl, IClearControl, IInnerContentControl, public void Clear() { + Focus(NavigationMethod.Pointer); _presenter?.SetValue(TimePickerPresenter.TimeProperty, null); } @@ -170,6 +171,7 @@ public class TimePicker : TemplatedControl, IClearControl, IInnerContentControl, private void OnButtonClick(object? sender, RoutedEventArgs e) { + Focus(NavigationMethod.Pointer); SetCurrentValue(IsDropdownOpenProperty, !IsDropdownOpen); } @@ -244,6 +246,7 @@ public class TimePicker : TemplatedControl, IClearControl, IInnerContentControl, { _presenter?.Confirm(); SetCurrentValue(IsDropdownOpenProperty, false); + TopLevel.GetTopLevel(this); Focus(); } diff --git a/src/Ursa/Controls/DateTimePicker/TimePickerPresenter.cs b/src/Ursa/Controls/DateTimePicker/TimePickerPresenter.cs index 50481af..b8d76b9 100644 --- a/src/Ursa/Controls/DateTimePicker/TimePickerPresenter.cs +++ b/src/Ursa/Controls/DateTimePicker/TimePickerPresenter.cs @@ -148,8 +148,8 @@ public class TimePickerPresenter : TemplatedControl _hourSelector?.SetValue(DateTimePickerPanel.ItemFormatProperty, part.ToLower()); if (_hourSelector is not null) { - _hourSelector.MaximumValue = _use12Clock ? 12 : 23; - _hourSelector.MinimumValue = _use12Clock ? 1 : 0; + _hourSelector.MaximumValue = _use12Clock ? 11 : 23; + _hourSelector.MinimumValue = 0; } } else if (part[0] == 'm' && !panels.Contains(_minuteSelector)) @@ -245,7 +245,7 @@ public class TimePickerPresenter : TemplatedControl if (_hourSelector is not null) { var index = _use12Clock ? time.Value.Hours % 12 : time.Value.Hours; - if (index == 0) index = 12; + if (_use12Clock && index == 12) index = 0; _hourSelector.SelectedValue = index; } @@ -269,7 +269,7 @@ public class TimePickerPresenter : TemplatedControl { _hourSelector.ItemFormat = "hh"; _hourSelector.MaximumValue = _use12Clock ? 12 : 23; - _hourSelector.MinimumValue = _use12Clock ? 1 : 0; + _hourSelector.MinimumValue = 0; } if (_minuteSelector is not null)