离开/更改页面时的 Xamarin.forms 事件

Hon*_*ála 4 c# events page-lifecycle xamarin xamarin.forms

我正在寻找类似函数的东西

protected override void OnDisappearing()
{
}
Run Code Online (Sandbox Code Playgroud)

在 Xamarin 表单中。问题是,即使我关闭手机显示屏,也会调用此功能。我正在寻找一种仅在页面更改时响应事件的功能 - 例如,菜单中的用户单击正在访问的页面以外的页面。

谢谢你的建议

Fab*_*e T 5

你需要结合OnBackButtonPressedOnDisappearing

OnAppearingOnDisappearing

您可以创建一个base实现OnBackButtonPressedand orOnDisappearing和 or的页面OnAppearing

然后将“活动”页面引用保存在静态变量中。

// this condition can help you concerning the screen on or off
if(this.Title == Activepage.Title) // or id
    return;
Run Code Online (Sandbox Code Playgroud)