Last active
August 4, 2021 07:23
-
-
Save nuitsjp/604ff746545f01c0aa029644f1e3ca62 to your computer and use it in GitHub Desktop.
Xamarin.FormsでOnSleep・OnResumeをViewModelでハンドルする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public partial class App : Application | |
{ | |
..... | |
protected override void OnSleep() | |
{ | |
(MainPage.BindingContext as IApplicationLifecycle)?.OnSleep(); | |
} | |
protected override void OnResume() | |
{ | |
(MainPage.BindingContext as IApplicationLifecycle)?.OnResume(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IApplicationLifecycle | |
{ | |
void OnSleep(); | |
void OnResume(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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