fix: fix DatePicker & TimePicker to respect custom Width property. (#737)

(cherry picked from commit 136d577667)
This commit is contained in:
Zhang Dian
2026-02-09 14:45:17 +08:00
parent ca6e04e18a
commit d5eec907a3
2 changed files with 12 additions and 8 deletions

View File

@@ -2,9 +2,10 @@
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.PreviewWith>
<Border Padding="20">
<StackPanel Margin="20">
<DatePickerPresenter />
</Border>
<DatePicker Width="500" />
</StackPanel>
</Design.PreviewWith>
<ControlTheme x:Key="{x:Type DatePickerPresenter}" TargetType="DatePickerPresenter">
<Setter Property="Width" Value="296" />
@@ -141,6 +142,7 @@
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="MinHeight" Value="{DynamicResource DateTimePickerButtonDefaultHeight}" />
<Setter Property="MinWidth" Value="296" />
<Setter Property="Template">
<ControlTemplate TargetType="DatePicker">
<DataValidationErrors>
@@ -152,8 +154,8 @@
Name="PART_FlyoutButton"
Grid.Column="0"
Grid.ColumnSpan="2"
Width="298"
MinWidth="298"
MinWidth="{TemplateBinding MinWidth}"
MaxWidth="{TemplateBinding MaxWidth}"
MinHeight="{TemplateBinding MinHeight}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"

View File

@@ -2,9 +2,10 @@
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.PreviewWith>
<Border Padding="20">
<StackPanel Margin="20">
<TimePickerPresenter />
</Border>
<TimePicker UseSeconds="True" Width="500" />
</StackPanel>
</Design.PreviewWith>
<ControlTheme x:Key="{x:Type TimePickerPresenter}" TargetType="TimePickerPresenter">
<Setter Property="Width" Value="242" />
@@ -163,6 +164,7 @@
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="MinHeight" Value="{DynamicResource DateTimePickerButtonDefaultHeight}" />
<Setter Property="MinWidth" Value="242" />
<Setter Property="Template">
<ControlTemplate>
<DataValidationErrors>
@@ -174,8 +176,8 @@
Name="PART_FlyoutButton"
Grid.Column="0"
Grid.ColumnSpan="2"
Width="242"
MinWidth="242"
MinWidth="{TemplateBinding MinWidth}"
MaxWidth="{TemplateBinding MaxWidth}"
MinHeight="{TemplateBinding MinHeight}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"