|
@@ -232,14 +232,9 @@ namespace Avalonia.Controls
|
|
internal const int RowsPerYear = 3;
|
|
internal const int RowsPerYear = 3;
|
|
internal const int ColumnsPerYear = 4;
|
|
internal const int ColumnsPerYear = 4;
|
|
|
|
|
|
- private DateTime? _selectedDate;
|
|
|
|
private DateTime _selectedMonth;
|
|
private DateTime _selectedMonth;
|
|
private DateTime _selectedYear;
|
|
private DateTime _selectedYear;
|
|
|
|
|
|
- private DateTime _displayDate = DateTime.Today;
|
|
|
|
- private DateTime? _displayDateStart;
|
|
|
|
- private DateTime? _displayDateEnd;
|
|
|
|
-
|
|
|
|
private bool _isShiftPressed;
|
|
private bool _isShiftPressed;
|
|
private bool _displayDateIsChanging;
|
|
private bool _displayDateIsChanging;
|
|
|
|
|
|
@@ -396,13 +391,13 @@ namespace Avalonia.Controls
|
|
}
|
|
}
|
|
case CalendarMode.Year:
|
|
case CalendarMode.Year:
|
|
{
|
|
{
|
|
- DisplayDate = SelectedMonth;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateProperty, SelectedMonth);
|
|
SelectedYear = SelectedMonth;
|
|
SelectedYear = SelectedMonth;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
case CalendarMode.Decade:
|
|
case CalendarMode.Decade:
|
|
{
|
|
{
|
|
- DisplayDate = SelectedYear;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateProperty, SelectedYear);
|
|
SelectedMonth = SelectedYear;
|
|
SelectedMonth = SelectedYear;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -472,7 +467,7 @@ namespace Avalonia.Controls
|
|
if (IsValidSelectionMode(e.NewValue!))
|
|
if (IsValidSelectionMode(e.NewValue!))
|
|
{
|
|
{
|
|
_displayDateIsChanging = true;
|
|
_displayDateIsChanging = true;
|
|
- SelectedDate = null;
|
|
|
|
|
|
+ SetCurrentValue(SelectedDateProperty, null);
|
|
_displayDateIsChanging = false;
|
|
_displayDateIsChanging = false;
|
|
SelectedDates.Clear();
|
|
SelectedDates.Clear();
|
|
}
|
|
}
|
|
@@ -497,11 +492,8 @@ namespace Avalonia.Controls
|
|
|| mode == CalendarSelectionMode.None;
|
|
|| mode == CalendarSelectionMode.None;
|
|
}
|
|
}
|
|
|
|
|
|
- public static readonly DirectProperty<Calendar, DateTime?> SelectedDateProperty =
|
|
|
|
- AvaloniaProperty.RegisterDirect<Calendar, DateTime?>(
|
|
|
|
- nameof(SelectedDate),
|
|
|
|
- o => o.SelectedDate,
|
|
|
|
- (o, v) => o.SelectedDate = v,
|
|
|
|
|
|
+ public static readonly StyledProperty<DateTime?> SelectedDateProperty =
|
|
|
|
+ AvaloniaProperty.Register<Calendar, DateTime?>(nameof(SelectedDate),
|
|
defaultBindingMode: BindingMode.TwoWay);
|
|
defaultBindingMode: BindingMode.TwoWay);
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -529,8 +521,8 @@ namespace Avalonia.Controls
|
|
/// </remarks>
|
|
/// </remarks>
|
|
public DateTime? SelectedDate
|
|
public DateTime? SelectedDate
|
|
{
|
|
{
|
|
- get { return _selectedDate; }
|
|
|
|
- set { SetAndRaise(SelectedDateProperty, ref _selectedDate, value); }
|
|
|
|
|
|
+ get => GetValue(SelectedDateProperty);
|
|
|
|
+ set => SetValue(SelectedDateProperty, value);
|
|
}
|
|
}
|
|
private void OnSelectedDateChanged(AvaloniaPropertyChangedEventArgs e)
|
|
private void OnSelectedDateChanged(AvaloniaPropertyChangedEventArgs e)
|
|
{
|
|
{
|
|
@@ -726,11 +718,8 @@ namespace Avalonia.Controls
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public static readonly DirectProperty<Calendar, DateTime> DisplayDateProperty =
|
|
|
|
- AvaloniaProperty.RegisterDirect<Calendar, DateTime>(
|
|
|
|
- nameof(DisplayDate),
|
|
|
|
- o => o.DisplayDate,
|
|
|
|
- (o, v) => o.DisplayDate = v,
|
|
|
|
|
|
+ public static readonly StyledProperty<DateTime> DisplayDateProperty =
|
|
|
|
+ AvaloniaProperty.Register<Calendar, DateTime>(nameof(DisplayDate),
|
|
defaultBindingMode: BindingMode.TwoWay);
|
|
defaultBindingMode: BindingMode.TwoWay);
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -760,8 +749,8 @@ namespace Avalonia.Controls
|
|
/// </remarks>
|
|
/// </remarks>
|
|
public DateTime DisplayDate
|
|
public DateTime DisplayDate
|
|
{
|
|
{
|
|
- get { return _displayDate; }
|
|
|
|
- set { SetAndRaise(DisplayDateProperty, ref _displayDate, value); }
|
|
|
|
|
|
+ get => GetValue(DisplayDateProperty);
|
|
|
|
+ set => SetValue(DisplayDateProperty, value);
|
|
}
|
|
}
|
|
internal DateTime DisplayDateInternal { get; private set; }
|
|
internal DateTime DisplayDateInternal { get; private set; }
|
|
|
|
|
|
@@ -796,11 +785,8 @@ namespace Avalonia.Controls
|
|
DisplayDateChanged?.Invoke(this, e);
|
|
DisplayDateChanged?.Invoke(this, e);
|
|
}
|
|
}
|
|
|
|
|
|
- public static readonly DirectProperty<Calendar, DateTime?> DisplayDateStartProperty =
|
|
|
|
- AvaloniaProperty.RegisterDirect<Calendar, DateTime?>(
|
|
|
|
- nameof(DisplayDateStart),
|
|
|
|
- o => o.DisplayDateStart,
|
|
|
|
- (o, v) => o.DisplayDateStart = v,
|
|
|
|
|
|
+ public static readonly StyledProperty<DateTime?> DisplayDateStartProperty =
|
|
|
|
+ AvaloniaProperty.Register<Calendar, DateTime?>(nameof(DisplayDateStart),
|
|
defaultBindingMode: BindingMode.TwoWay);
|
|
defaultBindingMode: BindingMode.TwoWay);
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets or sets the first date to be displayed.
|
|
/// Gets or sets the first date to be displayed.
|
|
@@ -814,8 +800,8 @@ namespace Avalonia.Controls
|
|
/// </remarks>
|
|
/// </remarks>
|
|
public DateTime? DisplayDateStart
|
|
public DateTime? DisplayDateStart
|
|
{
|
|
{
|
|
- get { return _displayDateStart; }
|
|
|
|
- set { SetAndRaise(DisplayDateStartProperty, ref _displayDateStart, value); }
|
|
|
|
|
|
+ get => GetValue(DisplayDateStartProperty);
|
|
|
|
+ set => SetValue(DisplayDateStartProperty, value);
|
|
}
|
|
}
|
|
private void OnDisplayDateStartChanged(AvaloniaPropertyChangedEventArgs e)
|
|
private void OnDisplayDateStartChanged(AvaloniaPropertyChangedEventArgs e)
|
|
{
|
|
{
|
|
@@ -831,7 +817,7 @@ namespace Avalonia.Controls
|
|
|
|
|
|
if (selectedDateMin.HasValue && DateTime.Compare(selectedDateMin.Value, newValue.Value) < 0)
|
|
if (selectedDateMin.HasValue && DateTime.Compare(selectedDateMin.Value, newValue.Value) < 0)
|
|
{
|
|
{
|
|
- DisplayDateStart = selectedDateMin.Value;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateStartProperty, selectedDateMin.Value);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -839,14 +825,14 @@ namespace Avalonia.Controls
|
|
// DisplayDateEnd = DisplayDateStart
|
|
// DisplayDateEnd = DisplayDateStart
|
|
if (DateTime.Compare(newValue.Value, DisplayDateRangeEnd) > 0)
|
|
if (DateTime.Compare(newValue.Value, DisplayDateRangeEnd) > 0)
|
|
{
|
|
{
|
|
- DisplayDateEnd = DisplayDateStart;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateEndProperty, DisplayDateStart);
|
|
}
|
|
}
|
|
|
|
|
|
// If DisplayDate < DisplayDateStart,
|
|
// If DisplayDate < DisplayDateStart,
|
|
// DisplayDate = DisplayDateStart
|
|
// DisplayDate = DisplayDateStart
|
|
if (DateTimeHelper.CompareYearMonth(newValue.Value, DisplayDateInternal) > 0)
|
|
if (DateTimeHelper.CompareYearMonth(newValue.Value, DisplayDateInternal) > 0)
|
|
{
|
|
{
|
|
- DisplayDate = newValue.Value;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateProperty, newValue.Value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
UpdateMonths();
|
|
UpdateMonths();
|
|
@@ -905,11 +891,8 @@ namespace Avalonia.Controls
|
|
get { return DisplayDateStart.GetValueOrDefault(DateTime.MinValue); }
|
|
get { return DisplayDateStart.GetValueOrDefault(DateTime.MinValue); }
|
|
}
|
|
}
|
|
|
|
|
|
- public static readonly DirectProperty<Calendar, DateTime?> DisplayDateEndProperty =
|
|
|
|
- AvaloniaProperty.RegisterDirect<Calendar, DateTime?>(
|
|
|
|
- nameof(DisplayDateEnd),
|
|
|
|
- o => o.DisplayDateEnd,
|
|
|
|
- (o, v) => o.DisplayDateEnd = v,
|
|
|
|
|
|
+ public static readonly StyledProperty<DateTime?> DisplayDateEndProperty =
|
|
|
|
+ AvaloniaProperty.Register<Calendar, DateTime?>(nameof(DisplayDateEnd),
|
|
defaultBindingMode: BindingMode.TwoWay);
|
|
defaultBindingMode: BindingMode.TwoWay);
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -924,8 +907,8 @@ namespace Avalonia.Controls
|
|
/// </remarks>
|
|
/// </remarks>
|
|
public DateTime? DisplayDateEnd
|
|
public DateTime? DisplayDateEnd
|
|
{
|
|
{
|
|
- get { return _displayDateEnd; }
|
|
|
|
- set { SetAndRaise(DisplayDateEndProperty, ref _displayDateEnd, value); }
|
|
|
|
|
|
+ get => GetValue(DisplayDateEndProperty);
|
|
|
|
+ set => SetValue(DisplayDateEndProperty, value);
|
|
}
|
|
}
|
|
|
|
|
|
private void OnDisplayDateEndChanged(AvaloniaPropertyChangedEventArgs e)
|
|
private void OnDisplayDateEndChanged(AvaloniaPropertyChangedEventArgs e)
|
|
@@ -942,7 +925,7 @@ namespace Avalonia.Controls
|
|
|
|
|
|
if (selectedDateMax.HasValue && DateTime.Compare(selectedDateMax.Value, newValue.Value) > 0)
|
|
if (selectedDateMax.HasValue && DateTime.Compare(selectedDateMax.Value, newValue.Value) > 0)
|
|
{
|
|
{
|
|
- DisplayDateEnd = selectedDateMax.Value;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateEndProperty, selectedDateMax.Value);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -950,7 +933,7 @@ namespace Avalonia.Controls
|
|
// DisplayDateEnd = DisplayDateStart
|
|
// DisplayDateEnd = DisplayDateStart
|
|
if (DateTime.Compare(newValue.Value, DisplayDateRangeStart) < 0)
|
|
if (DateTime.Compare(newValue.Value, DisplayDateRangeStart) < 0)
|
|
{
|
|
{
|
|
- DisplayDateEnd = DisplayDateStart;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateEndProperty, DisplayDateStart);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -958,7 +941,7 @@ namespace Avalonia.Controls
|
|
// DisplayDate = DisplayDateEnd
|
|
// DisplayDate = DisplayDateEnd
|
|
if (DateTimeHelper.CompareYearMonth(newValue.Value, DisplayDateInternal) < 0)
|
|
if (DateTimeHelper.CompareYearMonth(newValue.Value, DisplayDateInternal) < 0)
|
|
{
|
|
{
|
|
- DisplayDate = newValue.Value;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateProperty, newValue.Value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
UpdateMonths();
|
|
UpdateMonths();
|
|
@@ -1284,7 +1267,7 @@ namespace Avalonia.Controls
|
|
{
|
|
{
|
|
LastSelectedDate = d.Value;
|
|
LastSelectedDate = d.Value;
|
|
}
|
|
}
|
|
- DisplayDate = d.Value;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateProperty, d.Value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -1332,7 +1315,7 @@ namespace Avalonia.Controls
|
|
{
|
|
{
|
|
LastSelectedDate = d.Value;
|
|
LastSelectedDate = d.Value;
|
|
}
|
|
}
|
|
- DisplayDate = d.Value;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateProperty, d.Value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -1719,7 +1702,7 @@ namespace Avalonia.Controls
|
|
if (ctrl)
|
|
if (ctrl)
|
|
{
|
|
{
|
|
SelectedMonth = DisplayDateInternal;
|
|
SelectedMonth = DisplayDateInternal;
|
|
- DisplayMode = CalendarMode.Year;
|
|
|
|
|
|
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Year);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -1733,7 +1716,7 @@ namespace Avalonia.Controls
|
|
if (ctrl)
|
|
if (ctrl)
|
|
{
|
|
{
|
|
SelectedYear = SelectedMonth;
|
|
SelectedYear = SelectedMonth;
|
|
- DisplayMode = CalendarMode.Decade;
|
|
|
|
|
|
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Decade);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -1770,8 +1753,8 @@ namespace Avalonia.Controls
|
|
{
|
|
{
|
|
if (ctrl)
|
|
if (ctrl)
|
|
{
|
|
{
|
|
- DisplayDate = SelectedMonth;
|
|
|
|
- DisplayMode = CalendarMode.Month;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateProperty, SelectedMonth);
|
|
|
|
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Month);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -1785,7 +1768,7 @@ namespace Avalonia.Controls
|
|
if (ctrl)
|
|
if (ctrl)
|
|
{
|
|
{
|
|
SelectedMonth = SelectedYear;
|
|
SelectedMonth = SelectedYear;
|
|
- DisplayMode = CalendarMode.Year;
|
|
|
|
|
|
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Year);
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -1850,14 +1833,14 @@ namespace Avalonia.Controls
|
|
{
|
|
{
|
|
case CalendarMode.Year:
|
|
case CalendarMode.Year:
|
|
{
|
|
{
|
|
- DisplayDate = SelectedMonth;
|
|
|
|
- DisplayMode = CalendarMode.Month;
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateProperty, SelectedMonth);
|
|
|
|
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Month);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
case CalendarMode.Decade:
|
|
case CalendarMode.Decade:
|
|
{
|
|
{
|
|
SelectedMonth = SelectedYear;
|
|
SelectedMonth = SelectedYear;
|
|
- DisplayMode = CalendarMode.Year;
|
|
|
|
|
|
+ SetCurrentValue(DisplayModeProperty, CalendarMode.Year);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2103,7 +2086,8 @@ namespace Avalonia.Controls
|
|
/// </summary>
|
|
/// </summary>
|
|
public Calendar()
|
|
public Calendar()
|
|
{
|
|
{
|
|
- UpdateDisplayDate(this, this.DisplayDate, DateTime.MinValue);
|
|
|
|
|
|
+ SetCurrentValue(DisplayDateProperty, DateTime.Today);
|
|
|
|
+ UpdateDisplayDate(this, DisplayDate, DateTime.MinValue);
|
|
BlackoutDates = new CalendarBlackoutDatesCollection(this);
|
|
BlackoutDates = new CalendarBlackoutDatesCollection(this);
|
|
SelectedDates = new SelectedDatesCollection(this);
|
|
SelectedDates = new SelectedDatesCollection(this);
|
|
RemovedItems = new Collection<DateTime>();
|
|
RemovedItems = new Collection<DateTime>();
|