diff --git a/demo/Ursa.Demo/Pages/DatePickerDemo.axaml b/demo/Ursa.Demo/Pages/DatePickerDemo.axaml index a946536..dbe53bf 100644 --- a/demo/Ursa.Demo/Pages/DatePickerDemo.axaml +++ b/demo/Ursa.Demo/Pages/DatePickerDemo.axaml @@ -7,6 +7,7 @@ x:Class="Ursa.Demo.Pages.DatePickerDemo"> + diff --git a/src/Ursa.Themes.Semi/Controls/Calendar.axaml b/src/Ursa.Themes.Semi/Controls/Calendar.axaml index ca83de8..4fb4f39 100644 --- a/src/Ursa.Themes.Semi/Controls/Calendar.axaml +++ b/src/Ursa.Themes.Semi/Controls/Calendar.axaml @@ -4,7 +4,7 @@ xmlns:u="https://irihi.tech/ursa"> - + @@ -42,13 +42,13 @@ - + - + @@ -121,6 +121,7 @@ + @@ -152,13 +153,20 @@ Foreground="{DynamicResource CalendarItemIconForeground}" /> - - + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Ursa/Controls/DateTimePicker/Calendar.cs b/src/Ursa/Controls/DateTimePicker/Calendar.cs index 02288ba..0c79d3b 100644 --- a/src/Ursa/Controls/DateTimePicker/Calendar.cs +++ b/src/Ursa/Controls/DateTimePicker/Calendar.cs @@ -4,6 +4,7 @@ using Avalonia.Controls; using Avalonia.Controls.Metadata; using Avalonia.Controls.Primitives; using Avalonia.Interactivity; +using Irihi.Avalonia.Shared.Helpers; namespace Ursa.Controls; @@ -11,8 +12,9 @@ namespace Ursa.Controls; [TemplatePart(PART_PreviousYearButton, typeof(Button))] [TemplatePart(PART_NextButton, typeof(Button))] [TemplatePart(PART_PreviousButton, typeof(Button))] +[TemplatePart(PART_YearButton, typeof(Button))] +[TemplatePart(PART_MonthButton, typeof(Button))] [TemplatePart(PART_HeaderButton, typeof(Button))] -[TemplatePart(PART_BackButton, typeof(Button))] [TemplatePart(PART_MonthView, typeof(CalendarMonthView))] [TemplatePart(PART_YearView, typeof(CalendarYearView))] public class Calendar: TemplatedControl @@ -21,14 +23,18 @@ public class Calendar: TemplatedControl public const string PART_PreviousYearButton = "PART_PreviousYearButton"; public const string PART_NextButton = "PART_NextButton"; public const string PART_PreviousButton = "PART_PreviousButton"; - public const string PART_HeaderButton = "PART_HeaderButton"; - public const string PART_BackButton = "PART_BackButton"; + public const string PART_YearButton = "PART_YearButton"; + public const string PART_MonthButton = "PART_MonthButton"; public const string PART_MonthView = "PART_MonthView"; public const string PART_YearView = "PART_YearView"; + public const string PART_HeaderButton = "PART_HeaderButton"; private CalendarMonthView? _monthView; private CalendarYearView? _yearView; private DatePickerState _state = DatePickerState.None; + private Button? _yearButton; + private Button? _monthButton; + private Button? _headerButton; public static readonly StyledProperty SelectedDateProperty = AvaloniaProperty.Register(nameof(SelectedDate), DateTime.Now); @@ -73,6 +79,17 @@ public class Calendar: TemplatedControl set => SetValue(BlackoutDateRuleProperty, value); } + private bool _isMonthMode = true; + + public static readonly DirectProperty IsMonthModeProperty = AvaloniaProperty.RegisterDirect( + nameof(IsMonthMode), o => o.IsMonthMode, (o, v) => o.IsMonthMode = v); + + public bool IsMonthMode + { + get => _isMonthMode; + set => SetAndRaise(IsMonthModeProperty, ref _isMonthMode, value); + } + internal DateTime? StartDate; internal DateTime? EndDate; @@ -84,13 +101,50 @@ public class Calendar: TemplatedControl _monthView.OnDateSelected -= OnDateSelected; _monthView.OnDatePreviewed -= OnDatePreviewed; } + + if (_yearView is not null) + { + _yearView.OnMonthSelected -= OnMonthSelected; + } + Button.ClickEvent.RemoveHandler(OnYearButtonClick, _yearButton); + Button.ClickEvent.RemoveHandler(OnMonthButtonClick, _monthButton); _monthView = e.NameScope.Find(PART_MonthView); _yearView = e.NameScope.Find(PART_YearView); + _yearButton = e.NameScope.Find