Skip to content

CalendarDatePicker becomes unusable if closed programmatically #18418

@ds1709

Description

@ds1709

Describe the bug

If CalendarDatePicker is closed programmaticale when SelectedDate changed, it becomes unusable because of closing automatically when pointing on date, but not clicking on it.

To Reproduce

This is a simple behavior to reproduce:

internal class CalendarDatePickerBehavior : Behavior<CalendarDatePicker>
{
    protected override void OnAttached()
    {
        base.OnAttached();
        AssociatedObject!.PropertyChanged += AssociatedObjectPropertyChanged;
    }

    private async void AssociatedObjectPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
    {
        if (e.Property == CalendarDatePicker.SelectedDateProperty)
        {
            var w = new Window { Content = "Loading" };
            w.Show();
            await Task.Delay(100);
            w.Close();
        }
    }
}

Expected behavior

No response

Avalonia version

11.2.5

OS

No response

Additional context

CalendarDatePickerBehavior imitates situation when selecting date starts some long operation with blocking modal window. When window is shown, CalendarDatePicker closes automatically. There's boolean flag _isMouseLeftButtonDown in class CalendarItem. It sets to true when user press on it (Cell_Click) and sets to false on release (Cell_MouseLeftButtonUp). But when window is shown, CalendareDatePicker closes before Cell_MouseLeftButtonUp call. So, the _isMouseLeftButtonDown left true permanently.

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