-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Unloaded event behaviour in CollectionView header control inconsistent between Android and iOS #21331
Description
Description
I have a collectionview with a custom graph control in the header. This control does a bit of setup in its constructor to wire up event handlers for gestures etc. When the page is closed, I use the unloaded event of the control to clean up these event handlers.
This was working great in .Net 7 but is now not behaving the same way in .Net 8 on Android.
The Unloaded event of the control in the header is now firing whenever the collectionview items update, even though it's bound to different data and doesn't need to redraw, which deregisters all my event handlers and the gestures stop working.
This does not happen on iOS and never used to happen in Net 7. The Unloaded event of the control in the header does not fire when the items refresh on iOS or in Net 7
I'm not sure which is the correct behaviour (whether it should be firing or not), but it never used to fire when I built the page in Net 7 a few months ago. Now that we've bumped our app to Net 8 it behaves differently on Android and iOS.
I have just noticed now that Loaded event is also fired again on Android so I can move my event handler setup to there to fix the issue, but the behaviour is still different on Android and iOS.
Here are the repos to reproduce the issue. I have also included a net 7 version of the test app to show that it was working before.
.Net 8 version - Unloaded event for control in header fires on android when collectionview items refresh
https://gooseza.visualstudio.com/MauiBugs/_git/CollectionViewHeaderUnloadEventNet8
.Net 7 version - Unloaded doesn't fire for either Android or iOS
https://gooseza.visualstudio.com/MauiBugs/_git/CollectionViewHeaderUnloadEventNet7
Steps to Reproduce
Use the provided projects in the repos.
- Run the app and put a break point in the Unloaded event handler in CustomLabel control.
- Click the button to populate the list control.
- You will see in Net 8 that the unloaded event for the control in the header is triggered on Android but not iOS.
- If you do the same for the Net 7 version, you will see that neither Android not iOS trigger the unloaded event.
Link to public reproduction project repository
https://gooseza.visualstudio.com/MauiBugs/_git/CollectionViewHeaderUnloadEventNet8
Version with bug
8.0.7 SR2
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
7.0.92
Affected platforms
Android
Affected platform versions
Android 11, 12, 13
Did you find any workaround?
Yes, I can move my event setup into the Loaded method instead of doing it in the constructor, however the behaviour is still different on iOS and Android in Net 8, with the control only unloading and then loading again on Android, not iOS
Relevant log output
No response