Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CalendarView issue when shown for the second time #16123

Open
FrozDark opened this issue Apr 4, 2024 · 4 comments · Fixed by #16136
Open

CalendarView issue when shown for the second time #16123

FrozDark opened this issue Apr 4, 2024 · 4 comments · Fixed by #16136
Assignees
Labels
area/date-time-pickers DatePicker, TimePicker, CalendarDatePicker... difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working

Comments

@FrozDark
Copy link

FrozDark commented Apr 4, 2024

Current behavior

When the calendar is shown the second time it gets bugged with no interaction possible

Tested on Skia.WPF and Android have the same issue

qtagsag

Expected behavior

No bug

How to reproduce it (as minimally and precisely as possible)

CalendarViewIssue.zip

Workaround

No response

Works on UWP/WinUI

Yes

Environment

Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia

NuGet package version(s)

Tested on 5.2.0-dev.484 and 5.3.0-dev.12

Affected platforms

Android, iOS, Skia (WPF), Skia (GTK on Linux/macOS/Windows), Skia (Linux Framebuffer)

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

@FrozDark FrozDark added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Apr 4, 2024
@jeromelaban jeromelaban added area/date-time-pickers DatePicker, TimePicker, CalendarDatePicker... and removed triage/untriaged Indicates an issue requires triaging or verification labels Apr 4, 2024
@Youssef1313
Copy link
Member

It's crashing during measure:

      System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
         at System.Collections.Generic.List`1.get_Item(Int32 index)
         at Microsoft.UI.Xaml.Controls.Primitives.CalendarPanel.ContainersCache.GetOrCreate(Int32 index) in /__w/1/s/src/Uno.UI/UI/Xaml/Controls/CalendarView/Primitives/CalendarPanel.ModernCollectionBasePanel.cs:line 252
         at Microsoft.UI.Xaml.Controls.Primitives.CalendarPanel.base_MeasureOverride(Size availableSize) in /__w/1/s/src/Uno.UI/UI/Xaml/Controls/CalendarView/Primitives/CalendarPanel.ModernCollectionBasePanel.cs:line 590

@Youssef1313
Copy link
Member

NOTE: There is this piece of code:

#if HAS_UNO
        static readonly Dictionary<Type, WeakReference<ContentDialog>> DialogInstances = new();
        public static T GetDialog<T>(XamlRoot xamlRoot) where T : ContentDialog
        {
            T dialog;
            if (!DialogInstances.TryGetValue(typeof(T), out var dialogRef))
            {
                dialog = (T)Activator.CreateInstance(typeof(T), true);

                DialogInstances[typeof(T)] = new(dialog);
            }
            else if (!dialogRef.TryGetTarget(out var target))
            {
                dialog = (T)Activator.CreateInstance(typeof(T), true);
                dialogRef.SetTarget(dialog);
            }
            else
            {
                dialog = (T)target;
            }

            dialog.XamlRoot = xamlRoot;

            return dialog;
        }
#else
        public static T GetDialog<T>(XamlRoot xamlRoot) where T : ContentDialog
        {
            var dialog = (T)Activator.CreateInstance(typeof(T), true);
            dialog.XamlRoot = xamlRoot;

            return dialog;
        }
#endif

Using the "else" path in Uno makes it not crash. Investigating further as using the HAS_UNO path in WinUI doesn't crash in WinUI.

@FrozDark
Copy link
Author

FrozDark commented Apr 5, 2024

NOTE: There is this piece of code:

#if HAS_UNO
        static readonly Dictionary<Type, WeakReference<ContentDialog>> DialogInstances = new();
        public static T GetDialog<T>(XamlRoot xamlRoot) where T : ContentDialog
        {
            T dialog;
            if (!DialogInstances.TryGetValue(typeof(T), out var dialogRef))
            {
                dialog = (T)Activator.CreateInstance(typeof(T), true);

                DialogInstances[typeof(T)] = new(dialog);
            }
            else if (!dialogRef.TryGetTarget(out var target))
            {
                dialog = (T)Activator.CreateInstance(typeof(T), true);
                dialogRef.SetTarget(dialog);
            }
            else
            {
                dialog = (T)target;
            }

            dialog.XamlRoot = xamlRoot;

            return dialog;
        }
#else
        public static T GetDialog<T>(XamlRoot xamlRoot) where T : ContentDialog
        {
            var dialog = (T)Activator.CreateInstance(typeof(T), true);
            dialog.XamlRoot = xamlRoot;

            return dialog;
        }
#endif

Using the "else" path in Uno makes it not crash. Investigating further as using the HAS_UNO path in WinUI doesn't crash in WinUI.

As a workaround

It's been expected to have a new instance of the dialog to be working correctly as it will always show the control for the first time it's initialized

Also worth noting that It's working on stable 5.1.104

@Youssef1313
Copy link
Member

Youssef1313 commented Apr 5, 2024

The main root cause is that MaxDate changes between the two shows of the CalendarView. This is breaking the ContainersCache (it doesn't get cleared properly). Working on getting a PR soon-ish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/date-time-pickers DatePicker, TimePicker, CalendarDatePicker... difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants