Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Avalonia.Controls/DateTimePickers/DateTimePickerPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,22 @@ protected override void OnKeyDown(KeyEventArgs e)
base.OnKeyDown(e);
}

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);

if (change.Property == ItemHeightProperty)
{
foreach (var child in Children)
{
child.Height = ItemHeight;
}

UpdateHelperInfo();
_hasInit = false;
}
}

/// <summary>
/// Refreshes the content of the visible items
/// </summary>
Expand Down
36 changes: 36 additions & 0 deletions tests/Avalonia.Controls.UnitTests/DatePickerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,42 @@ public void Selector_ScrollUp_Should_Work(string selectorName)
public void Selector_ScrollDown_Should_Work(string selectorName)
=> TestSelectorScrolling(selectorName, panel => panel.ScrollDown());

[Theory]
[InlineData(false, 120d, 40d)]
[InlineData(true, 12000d, 6040d)]
public void Selector_ItemHeight_Change_Should_Update_Layout_State(
bool shouldLoop,
double expectedExtentHeight,
double expectedOffsetY)
{
using var app = UnitTestApplication.Start(Services);

var panel = new DateTimePickerPanel
{
MinimumValue = 1,
MaximumValue = 3,
ShouldLoop = shouldLoop,
ItemHeight = 20,
};

panel.Measure(new Size(100, 100));
panel.Arrange(new Rect(0, 0, 100, 100));
panel.SelectedValue = 2;

panel.ItemHeight = 40;

Assert.Equal(expectedExtentHeight, panel.Extent.Height);
Assert.Equal(expectedOffsetY, panel.Offset.Y);
Assert.All(panel.Children, child => Assert.Equal(40, child.Height));

panel.Measure(new Size(100, 100));
panel.Arrange(new Rect(0, 0, 100, 100));

var selectedItem = Assert.Single(panel.Children.OfType<ListBoxItem>().Where(item => item.IsSelected));
Assert.Equal(2, selectedItem.Tag);
Assert.Equal(50, selectedItem.Bounds.Center.Y);
}

private static void TestSelectorScrolling(string selectorName, Action<DateTimePickerPanel> scroll)
{
using var app = UnitTestApplication.Start(Services);
Expand Down