我有以下问题
我在 iOS 中的声明。当用户在后台返回应用程序时,我需要激活命令。在我的 ContentPage
上,我找不到识别返回的方法。在Android中,它可以正常工作,只有在iOS中,我在内容中找不到任何显示我正在返回的功能
protected override void OnAppearing()
{
Debug.WriteLine("OnAppearing()");
base.OnAppearing();
}
protected override void OnDisappearing()
{
Debug.WriteLine("OnDisappearing");
base.OnDisappearing();
}
protected override void OnBindingContextChanged()
{
Debug.WriteLine("OnBindingContextChanged");
base.OnBindingContextChanged();
}
我尝试了三个选项但没有结果
最佳答案
我通常这样做,所以我不必费心订阅:
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new MainPage();
}
protected override async void OnStart()
{
if (Application.Current.MainPage is IAppStateAware appStateAwarePage)
await appStateAwarePage.OnStartApplicationAsync();
if (Application.Current.MainPage.BindingContext is IAppStateAware appStateAwareVm)
await appStateAwareVm.OnStartApplicationAsync();
// Handle when your app starts
}
protected override async void OnSleep()
{
if (Application.Current.MainPage is IAppStateAware appStateAwarePage)
await appStateAwarePage.OnSleepApplicationAsync();
if (Application.Current.MainPage.BindingContext is IAppStateAware appStateAwareVm)
await appStateAwareVm.OnSleepApplicationAsync();
// Handle when your app sleeps
}
protected override async void OnResume()
{
if (Application.Current.MainPage is IAppStateAware appStateAwarePage)
await appStateAwarePage.OnResumeApplicationAsync();
if (Application.Current.MainPage.BindingContext is IAppStateAware appStateAwareVm)
await appStateAwareVm.OnResumeApplicationAsync();
// Handle when your app resumes
}
}
public class YourContentPage : Page, IAppStateAware
{
public Task OnResumeApplicationAsync()
{
throw new System.NotImplementedException();
}
public Task OnSleepApplicationAsync()
{
throw new System.NotImplementedException();
}
public Task OnStartApplicationAsync()
{
throw new System.NotImplementedException();
}
}
public interface IAppStateAware
{
Task OnResumeApplicationAsync();
Task OnSleepApplicationAsync();
Task OnStartApplicationAsync();
}
关于xamarin - 在内容页 XAMARIN 表单中调用 onresumo() 方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46201143/