Skip to content

Instantly share code, notes, and snippets.

@nuitsjp
Last active August 4, 2021 07:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nuitsjp/604ff746545f01c0aa029644f1e3ca62 to your computer and use it in GitHub Desktop.
Save nuitsjp/604ff746545f01c0aa029644f1e3ca62 to your computer and use it in GitHub Desktop.
Xamarin.FormsでOnSleep・OnResumeをViewModelでハンドルする
public partial class App : Application
{
.....
protected override void OnSleep()
{
(MainPage.BindingContext as IApplicationLifecycle)?.OnSleep();
}
protected override void OnResume()
{
(MainPage.BindingContext as IApplicationLifecycle)?.OnResume();
}
}
public interface IApplicationLifecycle
{
void OnSleep();
void OnResume();
}
public class MainPageViewModel : IApplicationLifecycle
{
public void OnSleep()
{
}
public void OnResume()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment