[英]Prism and Xamarin.Forms: IApplicationLifecycle
我有一個從BindableBase繼承並實現IApplicationLifecycle的視圖模型。 但是,iOS和android都不會調用IApplicationLifecycle.OnResume()和IApplicationLifecycle.OnSleep()。
您如何使用IApplicationLifecycle? 我似乎找不到任何文檔。 提前致謝!
在我的App.xaml.cs中,我有:
NavigationService.NavigateAsync("NavigationPage/MainPage");
我的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
由於您位於TabbedPage中,因此僅在TabbedPage.CurrentPage(SelectedTab)上調用IApplicationAware方法,因為這是當前活動頁面。
順便說一句,您可以通過覆蓋應用類中的OnResume和OnSleep方法來更改此行為,以實現您的目標。 使用現有代碼作為指南: https : //github.com/PrismLibrary/Prism/blob/master/Source/Xamarin/Prism.Forms/PrismApplicationBase.cs#L171
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.