2017-10-05 26 views
0

私はBindableBaseを継承し、IApplicationLifecycleを実装するビューモデルを持っています。ただし、IApplicationLifecycle.OnResume()とIApplicationLifecycle.OnSleep()は、iOSとAndroidでは呼び出されません。プリズムとXamarin.Forms:IApplicationLifecycle

どのように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

アプリのページ構造と現在のナビゲーションスタックに関するさらに詳しい情報を提供する必要があります。 –

答えて

1

あなたはTabbedPageに入っているので、IApplicationAwareメソッドはTabbedPage.CurrentPage(SelectedTab)上でのみ呼び出されます。これは、現在のアクティブなページです。

ところで、この動作を変更するには、アプリクラスのOnResumeメソッドとOnSleepメソッドをオーバーライドして目標を達成します。既存のコードをガイドとして使用してください:https://github.com/PrismLibrary/Prism/blob/master/Source/Xamarin/Prism.Forms/PrismApplicationBase.cs#L171

関連する問題