Beispiel #1
0
        public MainViewModel(AppBootstrapper appBootstrapper, IViewStackService viewStackService = null, IFirebaseAuthService firebaseAuthService = null)
        {
            viewStackService    = viewStackService ?? Locator.Current.GetService <IViewStackService>();
            firebaseAuthService = firebaseAuthService ?? Locator.Current.GetService <IFirebaseAuthService>();

            MenuItems = GetMenuItems();

            NavigateToMenuItem = ReactiveCommand.CreateFromObservable <IPageViewModel, Unit>(
                pageVm => viewStackService.PushPage(pageVm, resetStack: true));

            this.WhenAnyValue(x => x.Selected)
            .Where(x => x != null)
            .StartWith(MenuItems.First())
            .Select(x => Locator.Current.GetService <IPageViewModel>(x.TargetType.FullName))
            .InvokeCommand(NavigateToMenuItem);

            SignOut = ReactiveCommand.Create(() => firebaseAuthService.SignOut());

            SignOut.Subscribe(_ => appBootstrapper.MainView = new SignInViewModel(appBootstrapper));
        }