我有一个viewmodel,它继承自BindableBase并实现IApplicationLifecycle。但是,IApplicationLifecycle。OnResume()和IApplicationLifecycle。OnSleep()在iOS和android上都没有被调用。
如何使用IApplicationLifecycle?我似乎找不到它的任何文档。提前感谢!
在我的应用程序中。xaml。cs我有:
NavigationService.NavigateAsync("NavigationPage/MainPage");
和我的主页。xaml如下所示:
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:PrismApp.Views;assembly=PrismApp"
xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="PrismApp.Views.MainPage"
Title="MainPage">
<TabbedPage.Children>
<local:APage Icon="tabicon_mapspage.png" />
<local:BPage Icon="tabicon_profilepage.png" />
<local:CPage Icon="tabicon_statuspage.png" />
</TabbedPage.Children>
最后,我的MainPageViewModel如下所示:
public class MainPageViewModel : BindableBase, IApplicationLifecycle
{
private string _title;
public string Title
{
get { return _title; }
set { SetProperty(ref _title, value); }
}
public void OnResume()
{
var debug = 42;
}
public void OnSleep()
{
var debug = 42;
}
}
https://github.com/RandomStuffAndCode/PrismApp