diff --git a/src/Avalonia.Controls/DateTimePickers/DatePicker.cs b/src/Avalonia.Controls/DateTimePickers/DatePicker.cs index 6c419b9c08..5d3311e8c6 100644 --- a/src/Avalonia.Controls/DateTimePickers/DatePicker.cs +++ b/src/Avalonia.Controls/DateTimePickers/DatePicker.cs @@ -17,69 +17,76 @@ namespace Avalonia.Controls /// Define the Property /// public static readonly DirectProperty DayFormatProperty = - AvaloniaProperty.RegisterDirect("DayFormat", + AvaloniaProperty.RegisterDirect(nameof(DayFormat), x => x.DayFormat, (x, v) => x.DayFormat = v); /// /// Defines the Property /// public static readonly DirectProperty DayVisibleProperty = - AvaloniaProperty.RegisterDirect("DayVisible", + AvaloniaProperty.RegisterDirect(nameof(DayVisible), x => x.DayVisible, (x, v) => x.DayVisible = v); /// /// Defines the Property /// public static readonly StyledProperty HeaderProperty = - AvaloniaProperty.Register("Header"); + AvaloniaProperty.Register(nameof(Header)); /// /// Defines the Property /// public static readonly StyledProperty HeaderTemplateProperty = - AvaloniaProperty.Register("HeaderTemplate"); + AvaloniaProperty.Register(nameof(HeaderTemplate)); /// /// Defines the Property /// public static readonly DirectProperty MaxYearProperty = - AvaloniaProperty.RegisterDirect("MaxYear", x => x.MaxYear, (x, v) => x.MaxYear = v); + AvaloniaProperty.RegisterDirect(nameof(MaxYear), + x => x.MaxYear, (x, v) => x.MaxYear = v); /// /// Defines the Property /// public static readonly DirectProperty MinYearProperty = - AvaloniaProperty.RegisterDirect("MinYear", x => x.MinYear, (x, v) => x.MinYear = v); + AvaloniaProperty.RegisterDirect(nameof(MinYear), + x => x.MinYear, (x, v) => x.MinYear = v); /// /// Defines the Property /// public static readonly DirectProperty MonthFormatProperty = - AvaloniaProperty.RegisterDirect("MonthFormat", x => x.MonthFormat, (x, v) => x.MonthFormat = v); + AvaloniaProperty.RegisterDirect(nameof(MonthFormat), + x => x.MonthFormat, (x, v) => x.MonthFormat = v); /// /// Defines the Property /// public static readonly DirectProperty MonthVisibleProperty = - AvaloniaProperty.RegisterDirect("MonthVisible", x => x.MonthVisible, (x, v) => x.MonthVisible = v); + AvaloniaProperty.RegisterDirect(nameof(MonthVisible), + x => x.MonthVisible, (x, v) => x.MonthVisible = v); /// /// Defiens the Property /// public static readonly DirectProperty YearFormatProperty = - AvaloniaProperty.RegisterDirect("YearFormat", x => x.YearFormat, (x, v) => x.YearFormat = v); + AvaloniaProperty.RegisterDirect(nameof(YearFormat), + x => x.YearFormat, (x, v) => x.YearFormat = v); /// /// Defines the Property /// public static readonly DirectProperty YearVisibleProperty = - AvaloniaProperty.RegisterDirect("YearVisible", x => x.YearVisible, (x, v) => x.YearVisible = v); + AvaloniaProperty.RegisterDirect(nameof(YearVisible), + x => x.YearVisible, (x, v) => x.YearVisible = v); /// /// Defines the Property /// public static readonly DirectProperty SelectedDateProperty = - AvaloniaProperty.RegisterDirect("SelectedDate", x => x.SelectedDate, (x, v) => x.SelectedDate = v); + AvaloniaProperty.RegisterDirect(nameof(SelectedDate), + x => x.SelectedDate, (x, v) => x.SelectedDate = v); //Template Items private Button _flyoutButton; @@ -385,7 +392,7 @@ namespace Avalonia.Controls if (_presenter == null) throw new InvalidOperationException("No DatePickerPresenter found"); - _presenter.Date = SelectedDate.HasValue ? SelectedDate.Value : DateTimeOffset.Now; + _presenter.Date = SelectedDate ?? DateTimeOffset.Now; _popup.IsOpen = true; diff --git a/src/Avalonia.Controls/DateTimePickers/DatePickerPresenter.cs b/src/Avalonia.Controls/DateTimePickers/DatePickerPresenter.cs index 8a5b374781..8b86e46e88 100644 --- a/src/Avalonia.Controls/DateTimePickers/DatePickerPresenter.cs +++ b/src/Avalonia.Controls/DateTimePickers/DatePickerPresenter.cs @@ -18,55 +18,64 @@ namespace Avalonia.Controls /// Defines the Property /// public static readonly DirectProperty DateProperty = - AvaloniaProperty.RegisterDirect("Date", x => x.Date, (x, v) => x.Date = v); + AvaloniaProperty.RegisterDirect(nameof(Date), + x => x.Date, (x, v) => x.Date = v); /// /// Defines the Property /// public static readonly DirectProperty DayFormatProperty = - DatePicker.DayFormatProperty.AddOwner(x => x.DayFormat, (x, v) => x.DayFormat = v); + DatePicker.DayFormatProperty.AddOwner(x => + x.DayFormat, (x, v) => x.DayFormat = v); /// /// Defines the Property /// public static readonly DirectProperty DayVisibleProperty = - DatePicker.DayVisibleProperty.AddOwner(x => x.DayVisible, (x, v) => x.DayVisible = v); + DatePicker.DayVisibleProperty.AddOwner(x => + x.DayVisible, (x, v) => x.DayVisible = v); /// /// Defines the Property /// public static readonly DirectProperty MaxYearProperty = - DatePicker.MaxYearProperty.AddOwner(x => x.MaxYear, (x, v) => x.MaxYear = v); + DatePicker.MaxYearProperty.AddOwner(x => + x.MaxYear, (x, v) => x.MaxYear = v); /// /// Defines the Property /// public static readonly DirectProperty MinYearProperty = - DatePicker.MinYearProperty.AddOwner(x => x.MinYear, (x, v) => x.MinYear = v); + DatePicker.MinYearProperty.AddOwner(x => + x.MinYear, (x, v) => x.MinYear = v); /// /// Defines the Property /// public static readonly DirectProperty MonthFormatProperty = - DatePicker.MonthFormatProperty.AddOwner(x => x.MonthFormat, (x, v) => x.MonthFormat = v); + DatePicker.MonthFormatProperty.AddOwner(x => + x.MonthFormat, (x, v) => x.MonthFormat = v); /// /// Defines the Property /// public static readonly DirectProperty MonthVisibleProperty = - DatePicker.MonthVisibleProperty.AddOwner(x => x.MonthVisible, (x, v) => x.MonthVisible = v); + DatePicker.MonthVisibleProperty.AddOwner(x => + x.MonthVisible, (x, v) => x.MonthVisible = v); /// /// Defines the Property /// public static readonly DirectProperty YearFormatProperty = - DatePicker.YearFormatProperty.AddOwner(x => x.YearFormat, (x, v) => x.YearFormat = v); + DatePicker.YearFormatProperty.AddOwner(x => + x.YearFormat, (x, v) => x.YearFormat = v); /// /// Defines the Property /// public static readonly DirectProperty YearVisibleProperty = - DatePicker.YearVisibleProperty.AddOwner(x => x.YearVisible, (x, v) => x.YearVisible = v); + DatePicker.YearVisibleProperty.AddOwner(x => + x.YearVisible, (x, v) => x.YearVisible = v); //Template Items private Grid _pickerContainer; diff --git a/src/Avalonia.Controls/DateTimePickers/DateTimePickerPanel.cs b/src/Avalonia.Controls/DateTimePickers/DateTimePickerPanel.cs index b50b4cab9a..7c74383d42 100644 --- a/src/Avalonia.Controls/DateTimePickers/DateTimePickerPanel.cs +++ b/src/Avalonia.Controls/DateTimePickers/DateTimePickerPanel.cs @@ -22,25 +22,25 @@ namespace Avalonia.Controls.Primitives /// Defines the property /// public static readonly StyledProperty ItemHeightProperty = - AvaloniaProperty.Register("ItemHeight", 40.0); + AvaloniaProperty.Register(nameof(ItemHeight), 40.0); /// /// Defines the property /// public static readonly StyledProperty PanelTypeProperty = - AvaloniaProperty.Register("PanelType"); + AvaloniaProperty.Register(nameof(PanelType)); /// /// Defines the property /// public static readonly StyledProperty ItemFormatProperty = - AvaloniaProperty.Register("ItemFormat", "yyyy"); + AvaloniaProperty.Register(nameof(ItemFormat), "yyyy"); /// /// Defines the property /// public static readonly StyledProperty ShouldLoopProperty = - AvaloniaProperty.Register("ShouldLoop"); + AvaloniaProperty.Register(nameof(ShouldLoop)); //Backing fields for properties private int _minimumValue = 1; diff --git a/src/Avalonia.Controls/DateTimePickers/TimePicker.cs b/src/Avalonia.Controls/DateTimePickers/TimePicker.cs index 8b80cd8414..3fa426b1d3 100644 --- a/src/Avalonia.Controls/DateTimePickers/TimePicker.cs +++ b/src/Avalonia.Controls/DateTimePickers/TimePicker.cs @@ -15,33 +15,34 @@ namespace Avalonia.Controls /// Defines the property /// public static readonly DirectProperty MinuteIncrementProperty = - AvaloniaProperty.RegisterDirect("MinuteIncrement", x => x.MinuteIncrement, - (x, v) => x.MinuteIncrement = v); + AvaloniaProperty.RegisterDirect(nameof(MinuteIncrement), + x => x.MinuteIncrement, (x, v) => x.MinuteIncrement = v); /// /// Defines the property /// public static readonly StyledProperty HeaderProperty = - AvaloniaProperty.Register("Header"); + AvaloniaProperty.Register(nameof(Header)); /// /// Defines the property /// public static readonly StyledProperty HeaderTemplateProperty = - AvaloniaProperty.Register("HeaderTemplate"); + AvaloniaProperty.Register(nameof(HeaderTemplate)); /// /// Defines the property /// public static readonly DirectProperty ClockIdentifierProperty = - AvaloniaProperty.RegisterDirect("ClockIdentifier", x => x.ClockIdentifier, - (x, v) => x.ClockIdentifier = v); + AvaloniaProperty.RegisterDirect(nameof(ClockIdentifier), + x => x.ClockIdentifier, (x, v) => x.ClockIdentifier = v); /// /// Defines the property /// public static readonly DirectProperty SelectedTimeProperty = - AvaloniaProperty.RegisterDirect("Time", x => x.SelectedTime, (x, v) => x.SelectedTime = v); + AvaloniaProperty.RegisterDirect(nameof(SelectedTime), + x => x.SelectedTime, (x, v) => x.SelectedTime = v); //Template Items private TimePickerPresenter _presenter; @@ -230,8 +231,6 @@ namespace Avalonia.Controls { var newTime = SelectedTime.Value; - bool clock12 = ClockIdentifier == "12HourClock"; - if (ClockIdentifier == "12HourClock") { var hr = newTime.Hours; @@ -265,7 +264,7 @@ namespace Avalonia.Controls private void OnFlyoutButtonClicked(object sender, Avalonia.Interactivity.RoutedEventArgs e) { - _presenter.Time = SelectedTime.HasValue ? SelectedTime.Value : DateTime.Now.TimeOfDay; + _presenter.Time = SelectedTime ?? DateTime.Now.TimeOfDay; _popup.IsOpen = true; diff --git a/src/Avalonia.Controls/DateTimePickers/TimePickerPresenter.cs b/src/Avalonia.Controls/DateTimePickers/TimePickerPresenter.cs index 0788cbfe95..5ab5b92e16 100644 --- a/src/Avalonia.Controls/DateTimePickers/TimePickerPresenter.cs +++ b/src/Avalonia.Controls/DateTimePickers/TimePickerPresenter.cs @@ -6,8 +6,6 @@ using System; namespace Avalonia.Controls { - //Combines TimePickerFlyout & TimePickerFlyoutPicker from WinUI - /// /// Defines the presenter used for selecting a time. Intended for use with /// but can be used independently @@ -32,7 +30,7 @@ namespace Avalonia.Controls /// Defines the property /// public static readonly DirectProperty TimeProperty = - AvaloniaProperty.RegisterDirect("Time", + AvaloniaProperty.RegisterDirect(nameof(Time), x => x.Time, (x, v) => x.Time = v); public TimePickerPresenter() @@ -100,7 +98,6 @@ namespace Avalonia.Controls get => _Time; set { - var old = _Time; SetAndRaise(TimeProperty, ref _Time, value); InitPicker(); }