2017-10-05 85 views
0

我有一個viewmodel從BindableBase繼承並實現IApplicationLifecycle。但是,IApplicationLifecycle.OnResume()和IApplicationLifecycle.OnSleep()永遠不會在iOS或Android上調用。棱鏡和Xamarin.Forms:應用程序生命週期

你如何使用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

+1

您需要提供更多關於應用程序的頁面結構以及當前導航堆棧的信息。 –

回答

相關問題