我在OnDisappearing()中调用一种方法来取消订阅消息。
我应该在base.OnDisappearing()之后执行此操作
protected override void OnDisappearing()
{
base.OnDisappearing();
Unsubscribe();
}
或在base.OnDisappearing()之前
protected override void OnDisappearing()
{
Unsubscribe();
base.OnDisappearing();
}
private void Unsubscribe()
{
MessagingCenter.Unsubscribe<SettingsPageViewModel>(this, "OpenATIPage");
MessagingCenter.Unsubscribe<SettingsPageViewModel>(this, "OpenCFSPage");
MessagingCenter.Unsubscribe<SettingsPageViewModel>(this, "OpenCVMPage");
}
答案 0 :(得分:2)
根据我的经验,不确定其他开发人员的做法,这就是我用于OnAppearing
和OnDisappearing
的模式。
protected override void OnAppearing()
{
base.OnAppearing();
// User code for events and such
}
protected override void OnDisappearing()
{
// User code for events and such
base.OnDisappearing();
}
我喜欢在XF决定从OnDisappearing
事件中清除一些资源之前清除所有内容。另外,我喜欢在上班前打电话给XF OnAppearing
,这样他们就可以首先获取需要初始化的所有内容。