private IObservable <Unit> WhenLinked() { return(Observable .Defer( () => { return Observable .Start(() => ViewStackService.InsertPage(1, new RewardsViewModel()), RxApp.MainThreadScheduler) .Concat(ViewStackService.PopToPage(1)); })); }
public HomeViewModel(IViewStackService viewStackService) : base(viewStackService) { PushPage = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PushPage(new HomeViewModel(ViewStackService))); }); PushModalWithNav = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PushModal(new NavigationPageViewModel(new HomeViewModel(ViewStackService)))); }); PushModalWithoutNav = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PushModal(new HomeViewModel(ViewStackService))); }); PopModal = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService.PopModal()); }); var canPop = this.WhenAnyValue( vm => vm.PopCount, vm => vm.PageCount, (popCount, pageCount) => popCount > 0 && popCount < pageCount); PopPages = ReactiveCommand.CreateFromObservable( () => { return(ViewStackService .PopPages(_popCount ?? 0, true)); }, canPop); var canPopToNewPage = this.WhenAnyValue( vm => vm.PageIndex, pageIndex => pageIndex >= 0 && pageIndex < PageCount); PopToNewPage = ReactiveCommand.CreateFromObservable( () => { return(Observable .Start(() => ViewStackService.InsertPage(PageIndex ?? 0, new LoginViewModel(ViewStackService)), RxApp.MainThreadScheduler) .SelectMany(_ => ViewStackService.PopToPage(PageIndex ?? 0))); }, canPopToNewPage); this.WhenActivated( disposables => { _pageCount = ViewStackService .PageStack .Select( x => { return(x != null ? x.Count : 0); }) .ToProperty(this, vm => vm.PageCount, default(int), false, RxApp.MainThreadScheduler) .DisposeWith(disposables); }); }