Skip to content

Conversation

@Evan260
Copy link
Contributor

@Evan260 Evan260 commented Jan 18, 2026

What does the pull request do?

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

Related discussion: #15456

What is the current behavior?

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

<DatePicker Width="200" />  <!-- Content overflows -->
DateRange before

What is the updated/expected behavior with this PR?

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

<DatePicker Width="200" MinWidth="0" />  <!-- Content fits -->
DateRange after

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

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 DatePicker'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 DatePicker with custom Width.</TextBlock>
<StackPanel Orientation="Vertical">
    <Border BorderBrush="Red" BorderThickness="2" Width="200" HorizontalAlignment="Left">
        <DatePicker 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="DatePickerThemeMinWidth">0</x:Double>
        <x:Double x:Key="DatePickerThemeMaxWidth">1000</x:Double>
    </Grid.Resources>
    
    <DatePicker Width="200" HorizontalAlignment="Stretch" />
</Grid>

Breaking changes

None

Obsoletions / Deprecations

None

Fixed issues

Fixes #4862
Fixes #18592

@avaloniaui-bot
Copy link

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

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Jan 18, 2026

  • All contributors have signed the CLA.

@Evan260
Copy link
Contributor Author

Evan260 commented Jan 18, 2026

@cla-avalonia agree

@timunie timunie added enhancement area-fluent Fluent theme related backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Jan 18, 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 20, 2026 13:38
@avaloniaui-bot
Copy link

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

@avaloniaui-bot
Copy link

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

@MrJul MrJul added this pull request to the merge queue Jan 20, 2026
Merged via the queue into AvaloniaUI:master with commit 5f3dbae Jan 20, 2026
11 checks passed
@Evan260 Evan260 deleted the fix/datepicker-respect-width branch January 20, 2026 23:39
@Evan260
Copy link
Contributor Author

Evan260 commented Jan 21, 2026

I forgot to also update TimePicker, so I created a second PR for that.

BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}"
IsEnabled="{TemplateBinding IsEnabled}"
MinWidth="{DynamicResource DatePickerThemeMinWidth}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Does MinWidth still need to be specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. But I realized that TimePicker has the same problem as the DatePicker, so I made a PR for that here, and I added a commit to it to add the MinWidth back, just in case.

@rabbitism
Copy link
Contributor

@zdpcdt

MrJul added a commit that referenced this pull request Feb 12, 2026
@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.

Can I Change DatePicker Button's Column Length Dynamically? TimePicker and DatePicker controls have large minimum size

7 participants