Xamarin.FormsでOnSleep・OnResumeをViewModelでハンドルする
This file contains 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 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 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