Hi
My app has several 'ContentPages' which incorporate several 'ContentViews'. I have included UI elements (such as a status bar) into a ContentView which I can then display from any ContentPage.
My ContentViews have their own ViewModels, and in the case of the status bar, it subscribes to ConnectionStateChanged and DatabaseChanged events from my back end code, and needs to neatly unsubscribe when the Page that incorporates the view disappears.
Is there a way to neatly dispose of the viewmodel associated with a ContentView - I note that View's dont implement dispose, and that, unlike a ContentPage, there is no OnDissapearing event that I can manually tie up.
At the moment, in the onDissappearing override for the ContentPage that calls up my ContentViews, I am calling each of the Dispose methods I have added to the codebehind for my contentViews using the x:Name="xyz" tag from the Xaml thus:
protected override void OnDisappearing()
{
CompletedPatientEventsListCtrl.Dispose();
BleNfcConnectionControl.Dispose();
PatientEventsAwaitingCompletionCtrl.Dispose();
ProteusConnectionStatusCtrl.Dispose();
base.OnDisappearing();
}
My question is - is there a better way?
Nigel