From bc53fefafed008410554813a106687929eea3fef Mon Sep 17 00:00:00 2001 From: rabbitism Date: Wed, 19 Jun 2024 00:58:12 +0800 Subject: [PATCH] feat: wip. --- .../DateTimePicker/CalendarDisplayControl.cs | 61 ++++++----------- .../DateTimePicker/CalendarMonthView.cs | 66 ++++++++----------- .../DateTimePicker/CalendarYearView.cs | 6 +- .../Controls/DateTimePicker/DatePicker.cs | 2 +- .../Controls/DateTimePicker/DatePickerBase.cs | 46 +++++++++++++ .../Controls/DateTimePicker/IDateSelector.cs | 4 +- 6 files changed, 100 insertions(+), 85 deletions(-) create mode 100644 src/Ursa/Controls/DateTimePicker/DatePickerBase.cs diff --git a/src/Ursa/Controls/DateTimePicker/CalendarDisplayControl.cs b/src/Ursa/Controls/DateTimePicker/CalendarDisplayControl.cs index da45c49..633fcd4 100644 --- a/src/Ursa/Controls/DateTimePicker/CalendarDisplayControl.cs +++ b/src/Ursa/Controls/DateTimePicker/CalendarDisplayControl.cs @@ -31,54 +31,31 @@ public class CalendarDisplayControl: TemplatedControl private CalendarMonthView? _monthView; private CalendarYearView? _yearView; + // Year button only shows the year in month mode. private Button? _yearButton; + // Month button only shows the month in month mode. private Button? _monthButton; + // Header button shows year in year mode, and year range in higher mode. private Button? _headerButton; public event EventHandler? OnDateSelected; public event EventHandler? OnDatePreviewed; - - - public static readonly StyledProperty SelectedDateProperty = AvaloniaProperty.Register(nameof(SelectedDate), DateTime.Now); - public DateTime SelectedDate - { - get => GetValue(SelectedDateProperty); - set => SetValue(SelectedDateProperty, value); - } - public static readonly StyledProperty FirstDayOfWeekProperty = - AvaloniaProperty.Register(nameof(FirstDayOfWeek), - defaultValue: DateTimeHelper.GetCurrentDateTimeFormatInfo().FirstDayOfWeek); - public DayOfWeek FirstDayOfWeek - { - get => GetValue(FirstDayOfWeekProperty); - set => SetValue(FirstDayOfWeekProperty, value); - } - - public static readonly StyledProperty IsTodayHighlightedProperty = AvaloniaProperty.Register(nameof(IsTodayHighlighted), true); + public static readonly StyledProperty IsTodayHighlightedProperty = + DatePickerBase.IsTodayHighlightedProperty.AddOwner(); public bool IsTodayHighlighted { get => GetValue(IsTodayHighlightedProperty); set => SetValue(IsTodayHighlightedProperty, value); } - public static readonly StyledProperty?> BlackoutDatesProperty = - AvaloniaProperty.Register?>( - nameof(BlackoutDates)); - - public AvaloniaList? BlackoutDates + public static readonly StyledProperty FirstDayOfWeekProperty = + DatePickerBase.FirstDayOfWeekProperty.AddOwner(); + + public DayOfWeek FirstDayOfWeek { - get => GetValue(BlackoutDatesProperty); - set => SetValue(BlackoutDatesProperty, value); - } - - public static readonly StyledProperty BlackoutDateRuleProperty = AvaloniaProperty.Register( - nameof(BlackoutDateRule)); - - public IDateSelector? BlackoutDateRule - { - get => GetValue(BlackoutDateRuleProperty); - set => SetValue(BlackoutDateRuleProperty, value); + get => GetValue(FirstDayOfWeekProperty); + set => SetValue(FirstDayOfWeekProperty, value); } private bool _isMonthMode = true; @@ -92,16 +69,13 @@ public class CalendarDisplayControl: TemplatedControl set => SetAndRaise(IsMonthModeProperty, ref _isMonthMode, value); } - internal DateTime? StartDate; - internal DateTime? EndDate; - protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); if (_monthView is not null) { - _monthView.OnDateSelected -= OnDateSelected; - _monthView.OnDatePreviewed -= OnDatePreviewed; + _monthView.OnDateSelected -= OnMonthViewDateSelected; + _monthView.OnDatePreviewed -= OnMonthViewDatePreviewed; } if (_yearView is not null) @@ -118,8 +92,8 @@ public class CalendarDisplayControl: TemplatedControl _headerButton = e.NameScope.Find