2017-10-05 81 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

您需要提供更多关于应用程序的页面结构以及当前导航堆栈的信息。 –

回答

相关问题