feat: implement month syncing.

This commit is contained in:
rabbitism
2024-06-23 04:34:23 +08:00
parent c88258cdd5
commit d8119aaeaa
6 changed files with 90 additions and 30 deletions

View File

@@ -81,7 +81,10 @@ public class CalendarView : TemplatedControl
private void OnContextDateChanged(AvaloniaPropertyChangedEventArgs<CalendarContext> args)
{
ContextDateChanged?.Invoke(this, args.NewValue.Value);
if (!_dateContextSyncing)
{
ContextDateChanged?.Invoke(this, args.NewValue.Value);
}
//UpdateDayButtons();
//UpdateYearButtons();
}
@@ -571,4 +574,19 @@ public class CalendarView : TemplatedControl
base.OnPointerExited(e);
DatePreviewed?.Invoke(this, new CalendarDayButtonEventArgs(null));
}
private bool _dateContextSyncing = false;
/// <summary>
/// Used for syncing the context date for DateRangePicker. mark a flag to avoid infinitely loop.
/// </summary>
/// <param name="context"></param>
internal void SyncContextDate(CalendarContext? context)
{
if (context is null) return;
_dateContextSyncing = true;
ContextDate = context;
_dateContextSyncing = false;
UpdateDayButtons();
UpdateYearButtons();
}
}