Hello!
I am trying to Unsubscribe page-specific events when the page is no longer valid (ie. page has been popped off the NavigationStack). However, I can't find a reliable way to make this happen. Can someone help?
This is what I've tried:
1. Unsubscribe the events when you fire "PopAsync". This won't work because it won't fire when you a)press a physical "back" button or b) when the "back arrow" is pressed at the top of the screen.
2. Override OnBackButtonPressed(). This won't work because it only fires when the physical back button is pressed. I need an event that fires every time. Still have the issue with the back arrow at the top of the screen.
3. Override OnDisappearing(); This isn't a horrible solution... i can check to see if the page is part of the NavigationStack (base.Navigation.NavigationStack.FirstOrDefault(page => page == this); if it's null, then dispose of the events. Unfortunately, if it's NOT a modal, this always shows up and therefore the events are never unsubscribed.
Anyone have any ideas?