Reputation: 89
I'm looking for something like a function
protected override void OnDisappearing()
{
}
in Xamarin Forms. The problem is that this feature is called even when I turn off the phone display. I'm looking for a feature that only responds to the event when the page is changed - for example, the user in the menu clicks on a page other than the one that is being visited.
thanks for your advice
Upvotes: 4
Views: 4545
Reputation: 663
You will need to combine OnBackButtonPressed
and OnDisappearing
OR OnAppearing
and OnDisappearing
You can create a base
page which implement OnBackButtonPressed
and or OnDisappearing
and or OnAppearing
.
And you save "Active" page reference in a static variable.
// this condition can help you concerning the screen on or off
if(this.Title == Activepage.Title) // or id
return;
Upvotes: 5
Reputation: 38
What MVVM framework are you using? There are typically events built into the viewmodel that you can leverage.
If you want the page to do something specific on a button press then I'd suggest putting the code in there.
Upvotes: 0