Browse Source

Add VerticalContentAlignment property to DatePicker and TimePicker

This change registers VerticalContentAlignmentProperty as a
StyledProperty using ContentControl's property as the owner for both
DatePicker and TimePicker controls to maintain framework consistency.

Basic xUnit v3 unit tests are introduced to validate property
round-trips (Top, Center, Bottom, Stretch) and to ensure the default
value correctly resolves to Stretch. This establishes the necessary
C# infrastructure before modifying the control templates.

Part of #21211: implment fluent theme layout
pull/21464/head
João Cruz 4 months ago
parent
commit
daa8bd22df
  1. 15
      src/Avalonia.Controls/DateTimePickers/DatePicker.cs
  2. 14
      src/Avalonia.Controls/DateTimePickers/TimePicker.cs
  3. 18
      tests/Avalonia.Controls.UnitTests/DatePickerTests.cs
  4. 18
      tests/Avalonia.Controls.UnitTests/TimePickerTests.cs

15
src/Avalonia.Controls/DateTimePickers/DatePicker.cs

@ -75,6 +75,21 @@ namespace Avalonia.Controls
public static readonly StyledProperty<bool> YearVisibleProperty = public static readonly StyledProperty<bool> YearVisibleProperty =
AvaloniaProperty.Register<DatePicker, bool>(nameof(YearVisible), true); AvaloniaProperty.Register<DatePicker, bool>(nameof(YearVisible), true);
/// <summary>
/// Defines the <see cref="VerticalContentAlignment"/> property.
/// </summary>
public static readonly StyledProperty<VerticalAlignment> VerticalContentAlignmentProperty =
ContentControl.VerticalContentAlignmentProperty.AddOwner<DatePicker>();
/// <summary>
/// Gets or sets the vertical alignment of the content within the control.
/// </summary>
public VerticalAlignment VerticalContentAlignment
{
get => GetValue(VerticalContentAlignmentProperty);
set => SetValue(VerticalContentAlignmentProperty, value);
}
/// <summary> /// <summary>
/// Defines the <see cref="SelectedDate"/> Property /// Defines the <see cref="SelectedDate"/> Property
/// </summary> /// </summary>

14
src/Avalonia.Controls/DateTimePickers/TimePicker.cs

@ -50,6 +50,20 @@ namespace Avalonia.Controls
public static readonly StyledProperty<string> ClockIdentifierProperty = public static readonly StyledProperty<string> ClockIdentifierProperty =
AvaloniaProperty.Register<TimePicker, string>(nameof(ClockIdentifier), "12HourClock", coerce: CoerceClockIdentifier); AvaloniaProperty.Register<TimePicker, string>(nameof(ClockIdentifier), "12HourClock", coerce: CoerceClockIdentifier);
/// <summary>
/// Defines the <see cref="VerticalContentAlignment"/> property.
/// </summary>
public static readonly StyledProperty<VerticalAlignment> VerticalContentAlignmentProperty =
ContentControl.VerticalContentAlignmentProperty.AddOwner<TimePicker>();
/// <summary>
/// Gets or sets the vertical alignment of the content within the control.
/// </summary>
public VerticalAlignment VerticalContentAlignment
{
get => GetValue(VerticalContentAlignmentProperty);
set => SetValue(VerticalContentAlignmentProperty, value);
}
/// <summary> /// <summary>
/// Defines the <see cref="UseSeconds"/> property /// Defines the <see cref="UseSeconds"/> property
/// </summary> /// </summary>

18
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() private static IControlTemplate CreatePickerTemplate()
{ {
return new FuncControlTemplate((_, scope) => return new FuncControlTemplate((_, scope) =>

18
tests/Avalonia.Controls.UnitTests/TimePickerTests.cs

@ -466,5 +466,23 @@ namespace Avalonia.Controls.UnitTests
return contentPanel; 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);
}
} }
} }

Loading…
Cancel
Save