Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.forms event on leaving/changing the page

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

like image 864
Honza Hála Avatar asked Nov 02 '25 02:11

Honza Hála


1 Answers

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;
like image 157
Fabrice T Avatar answered Nov 03 '25 16:11

Fabrice T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!