Skip to content

DateTimePickerPanel.ItemHeight is not updated correctly after a dynamic resource change #22157

Description

@zrt2399

Describe the bug

When DateTimePickerPanel.ItemHeight is changed at runtime through a dynamic resource, the existing picker items keep stale layout state.

After changing DatePickerFlyoutPresenterItemHeight, the selected item height and the DatePicker popup position can be incorrect on the next open. The layout becomes correct only after another interaction or another layout update.

This is reproducible with the Fluent theme.

Image

To Reproduce

    <StackPanel x:Name="DatePickerHeightDemo"
                Margin="8"
                Spacing="8">
        <TextBlock Classes="h2">DatePicker dynamic item height (Fluent theme)</TextBlock>
        <TextBlock Text="Open and close the picker, change the height, then open it again." />
        <DatePicker x:Name="DynamicHeightDatePicker" VerticalContentAlignment="Center" />
        <Button Click="OnDatePickerHeightChanged">Change item height (40 / 60)</Button>
        <TextBlock x:Name="DatePickerHeightValue" Text="Current item height: 40" />
    </StackPanel>
    private bool _isLargeDatePickerHeight;

    private void OnDatePickerHeightChanged(object? sender, RoutedEventArgs e)
    {
        _isLargeDatePickerHeight = !_isLargeDatePickerHeight;
        var height = _isLargeDatePickerHeight ? 60d : 40d;
        DatePickerHeightDemo.Resources["DatePickerFlyoutPresenterItemHeight"] = height;
        DatePickerHeightDemo.Resources["DatePickerFlyoutPresenterHighlightHeight"] = height;
        DatePickerHeightValue.Text = $"Current item height: {height:0}";
    }

Expected behavior

No response

Avalonia version

12.1.2

OS

No response

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions