diff --git a/src/Avalonia.Controls/DateTimePickers/DatePicker.cs b/src/Avalonia.Controls/DateTimePickers/DatePicker.cs index 2f406252f7..c4206c7315 100644 --- a/src/Avalonia.Controls/DateTimePickers/DatePicker.cs +++ b/src/Avalonia.Controls/DateTimePickers/DatePicker.cs @@ -75,6 +75,21 @@ namespace Avalonia.Controls public static readonly StyledProperty YearVisibleProperty = AvaloniaProperty.Register(nameof(YearVisible), true); + /// + /// Defines the property. + /// + public static readonly StyledProperty VerticalContentAlignmentProperty = + ContentControl.VerticalContentAlignmentProperty.AddOwner(); + + /// + /// Gets or sets the vertical alignment of the content within the control. + /// + public VerticalAlignment VerticalContentAlignment + { + get => GetValue(VerticalContentAlignmentProperty); + set => SetValue(VerticalContentAlignmentProperty, value); + } + /// /// Defines the Property /// diff --git a/src/Avalonia.Controls/DateTimePickers/TimePicker.cs b/src/Avalonia.Controls/DateTimePickers/TimePicker.cs index 95d9e82782..7c6f96247f 100644 --- a/src/Avalonia.Controls/DateTimePickers/TimePicker.cs +++ b/src/Avalonia.Controls/DateTimePickers/TimePicker.cs @@ -50,6 +50,20 @@ namespace Avalonia.Controls public static readonly StyledProperty ClockIdentifierProperty = AvaloniaProperty.Register(nameof(ClockIdentifier), "12HourClock", coerce: CoerceClockIdentifier); + /// + /// Defines the property. + /// + public static readonly StyledProperty VerticalContentAlignmentProperty = + ContentControl.VerticalContentAlignmentProperty.AddOwner(); + + /// + /// Gets or sets the vertical alignment of the content within the control. + /// + public VerticalAlignment VerticalContentAlignment + { + get => GetValue(VerticalContentAlignmentProperty); + set => SetValue(VerticalContentAlignmentProperty, value); + } /// /// Defines the property /// diff --git a/tests/Avalonia.Controls.UnitTests/DatePickerTests.cs b/tests/Avalonia.Controls.UnitTests/DatePickerTests.cs index 4688a88fc5..523340a271 100644 --- a/tests/Avalonia.Controls.UnitTests/DatePickerTests.cs +++ b/tests/Avalonia.Controls.UnitTests/DatePickerTests.cs @@ -371,6 +371,24 @@ namespace Avalonia.Controls.UnitTests }); } + [Theory] + [InlineData(Avalonia.Layout.VerticalAlignment.Top)] + [InlineData(Avalonia.Layout.VerticalAlignment.Center)] + [InlineData(Avalonia.Layout.VerticalAlignment.Bottom)] + [InlineData(Avalonia.Layout.VerticalAlignment.Stretch)] + public void VerticalContentAlignment_RoundTrips(Avalonia.Layout.VerticalAlignment value) + { + var datePicker = new DatePicker { VerticalContentAlignment = value }; + Assert.Equal(value, datePicker.VerticalContentAlignment); + } + + [Fact] + public void VerticalContentAlignment_Default_Is_Stretch() + { + var datePicker = new DatePicker(); + Assert.Equal(Avalonia.Layout.VerticalAlignment.Stretch, datePicker.VerticalContentAlignment); + } + private static IControlTemplate CreatePickerTemplate() { return new FuncControlTemplate((_, scope) => diff --git a/tests/Avalonia.Controls.UnitTests/TimePickerTests.cs b/tests/Avalonia.Controls.UnitTests/TimePickerTests.cs index 11c52392f1..2c16c19f60 100644 --- a/tests/Avalonia.Controls.UnitTests/TimePickerTests.cs +++ b/tests/Avalonia.Controls.UnitTests/TimePickerTests.cs @@ -466,5 +466,23 @@ namespace Avalonia.Controls.UnitTests return contentPanel; }); } + + [Theory] + [InlineData(Avalonia.Layout.VerticalAlignment.Top)] + [InlineData(Avalonia.Layout.VerticalAlignment.Center)] + [InlineData(Avalonia.Layout.VerticalAlignment.Bottom)] + [InlineData(Avalonia.Layout.VerticalAlignment.Stretch)] + public void VerticalContentAlignment_RoundTrips(Avalonia.Layout.VerticalAlignment value) + { + var timePicker = new TimePicker { VerticalContentAlignment = value }; + Assert.Equal(value, timePicker.VerticalContentAlignment); + } + + [Fact] + public void VerticalContentAlignment_Default_Is_Stretch() + { + var timePicker = new TimePicker(); + Assert.Equal(Avalonia.Layout.VerticalAlignment.Stretch, timePicker.VerticalContentAlignment); + } } }