Skip to content

Implement VerticalContentAlignment for DatePicker and TimePicker - #21464

Merged
MrJul merged 4 commits into
AvaloniaUI:mainfrom
JoaoMSSCruz:feature/date-time-picker-alignment
Aug 19, 2026
Merged

Implement VerticalContentAlignment for DatePicker and TimePicker#21464
MrJul merged 4 commits into
AvaloniaUI:mainfrom
JoaoMSSCruz:feature/date-time-picker-alignment

Conversation

@JoaoMSSCruz

Copy link
Copy Markdown
Contributor

What does the pull request do?

This PR implements the VerticalContentAlignment property for both DatePicker and TimePicker controls. This allows developers to easily align the internal text and component selectors vertically without having to duplicate or override the default control templates.

What is the current behavior?

The internal content and textual selectors of the DatePicker and TimePicker controls have a fixed vertical position, meaning they do not respond to custom vertical alignment adjustments when the control height is increased.

What is the updated/expected behavior with this PR?

The internal text and selectors now dynamically bind and respond to the VerticalContentAlignment property. To verify the behavior at runtime, you can launch the ControlCatalog.Desktop sample, target the DatePicker or TimePicker controls, and inspect their visual tree using the Avalonia DevTools inspector to verify that the TemplateBinding propagates the alignment properties correctly down to the internal layout structures.

How was the solution implemented (if it's not obvious)?

  • Registered VerticalContentAlignmentProperty via ContentControl.VerticalContentAlignmentProperty.AddOwner() in both C# control classes.
  • Added standard CLR getters and setters to expose the property.
  • Applied the corresponding TemplateBinding VerticalContentAlignment mappings directly onto the internal container layout structures (PART_ButtonContentGrid for the DatePicker and PART_FlyoutButtonContentGrid for the TimePicker) across both Fluent and Simple XAML themes.

Checklist

Breaking changes

None.

Obsoletions / Deprecations

None.

Fixed issues

Fixes #21211

JoaoMSSCruz and others added 2 commits May 24, 2026 12:17
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 AvaloniaUI#21211: implment fluent theme layout
- Bind internal grids to VerticalContentAlignment in Fluent and Simple
  themes for DatePicker and TimePicker controls.
- Add comprehensive integration tests using mocked NameScopes in
  DatePickerTests and TimePickerTests to verify visual propagation.
- Validate visual layout correctness using the ControlCatalog app.

Closes AvaloniaUI#21211
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0065903-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added the backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch label Aug 13, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0068270-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general, some tests that aren't testing anything need to be removed, though.

Comment thread tests/Avalonia.Controls.UnitTests/TimePickerTests.cs Outdated
Comment thread tests/Avalonia.Controls.UnitTests/DatePickerTests.cs Outdated

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@MrJul
MrJul enabled auto-merge August 19, 2026 14:24
@MrJul
MrJul added this pull request to the merge queue Aug 19, 2026
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0068519-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Merged via the queue into AvaloniaUI:main with commit 9b5437b Aug 19, 2026
10 checks passed
MrJul added a commit to MrJul/Avalonia that referenced this pull request Sep 2, 2026
…loniaUI#21464)

* 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 AvaloniaUI#21211: implment fluent theme layout

* Fix VerticalContentAlignment bindings and integration tests

- Bind internal grids to VerticalContentAlignment in Fluent and Simple
  themes for DatePicker and TimePicker controls.
- Add comprehensive integration tests using mocked NameScopes in
  DatePickerTests and TimePickerTests to verify visual propagation.
- Validate visual layout correctness using the ControlCatalog app.

Closes AvaloniaUI#21211

* Remove tautological tests

---------

Co-authored-by: Martim Claudino <martimffclaudino@tecnico.ulisboa.pt>
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DatePicker and TimePicker do not provide a VerticalContentAlignment property.

4 participants