Skip to content

Conversation

@Evan260
Copy link
Contributor

@Evan260 Evan260 commented Jan 21, 2026

What does the pull request do?

Allows developers to set a custom Width on TimePicker without the content overflowing. Currently, the internal Button has a hardcoded MinWidth from TimePickerThemeMinWidth (242px) that cannot be overridden, preventing compact TimePickers in narrower layouts.

I made a PR to fix the DatePicker here, but I forgot to also update TimePicker. This PR is identical, except it addresses TimePicker instead.

What is the current behavior?

When setting Width="200" on a TimePicker, the content overflows because the internal Button enforces MinWidth=242 regardless of the control's Width setting.

<TimePicker Width="200" />  <!-- Content overflows -->
Before

What is the updated/expected behavior with this PR?

Developers can now create compact TimePickers by setting MinWidth="0":

<TimePicker Width="200" MinWidth="0" />  <!-- Content fits -->
After

Default behavior is unchanged - TimePickers without explicit MinWidth still use the theme default (242px).

How was the solution implemented?

  1. Added MinWidth and MaxWidth setters to the ControlTheme (preserves default appearance).
  2. Removed MinWidth from internal Button, changed MaxWidth to use TemplateBinding.

This allows the Button to shrink when the TimePicker's MinWidth is overridden, while maintaining backward compatibility.

How to test this new behavior:

Add to samples/ControlCatalog/Pages/DateTimePickerPage.xaml:

<TextBlock FontSize="18">A TimePicker with custom Width.</TextBlock>
<StackPanel Orientation="Vertical">
    <Border BorderBrush="Red" BorderThickness="2" Width="200" HorizontalAlignment="Left">
        <TimePicker Width="200" MinWidth="0" />
    </Border>
</StackPanel>

Workaround (for developers waiting for this fix)

Until this PR is merged, you can override the theme resources locally:

<Grid>
    <Grid.Resources>
        <x:Double x:Key="TimePickerThemeMinWidth">0</x:Double>
        <x:Double x:Key="TimePickerThemeMaxWidth">1000</x:Double>
    </Grid.Resources>
    
    <TimePicker Width="200" HorizontalAlignment="Stretch" />
</Grid>

Breaking changes

None

Obsoletions / Deprecations

None

@MrJul MrJul added enhancement area-fluent Fluent theme related backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Jan 21, 2026
Copy link
Member

@MrJul MrJul left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@MrJul MrJul enabled auto-merge January 21, 2026 08:20
@MrJul MrJul added this pull request to the merge queue Jan 21, 2026
@avaloniaui-bot
Copy link

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

Merged via the queue into AvaloniaUI:master with commit 65adcde Jan 21, 2026
12 checks passed
@Evan260 Evan260 deleted the fix/timepicker-respect-width branch January 21, 2026 19:01
MrJul pushed a commit that referenced this pull request Feb 12, 2026
* Fix TimePicker to respect Width by removing MinWidth from internal Button

* Add MinWidth to DatePicker for consistency
@MrJul MrJul added backported-11.3.x and removed backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Feb 12, 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.

3 participants