public MainPageViewModel(IScreen hostScreen) : base("main", hostScreen) { // Initialize all the page view models NewProjectViewModel newProjectPage = new NewProjectViewModel(this); AboutViewModel aboutPage = new AboutViewModel(this); // Initialize the commands for navigating to these pages OpenNewProjectPage = ReactiveCommand.CreateFromObservable(() => Router.Navigate.Execute(newProjectPage)); OpenAboutPage = ReactiveCommand.CreateFromObservable(() => Router.Navigate.Execute(aboutPage)); // Create the command for displaying the setup wizard at startup ReactiveCommand <Unit, Unit> cmdOpenSetupWizard = ReactiveCommand.CreateFromObservable <Unit, Unit>(sender => { return(ShowSetupWizard.Handle(Unit.Default)); }); // Check license status and optionally check for updates when the view is activated this.WhenActivated(disposables => { AppSettings.Default.Preferences.Reload(); if (AppSettings.Default.Preferences.CheckForUpdatesAtStartup) { aboutPage.CheckForUpdates.Execute().Subscribe().DisposeWith(disposables); } // Set the default (initial) page to the new project page Router.Navigate.Execute(newProjectPage).Subscribe().DisposeWith(disposables); }); newProjectPage.WhenActivated(disposables => { if (_firstActivation && AppSettings.Default.Preferences.ShowSetupWizardAtStartup) { cmdOpenSetupWizard.Execute().Subscribe().DisposeWith(disposables); _firstActivation = false; } }); //// Sample of a command executed periodically //TimeSpan interval = TimeSpan.FromHours(1); //Observable.Timer(interval, interval) // .Select(time => Unit.Default) // .InvokeCommand(aboutPage, p => p.CheckForUpdates); aboutPage.WhenAnyValue(p => p.IsNewVersionAvailable).BindTo(this, t => t.IsUpdateAvailable); Router.CurrentViewModel .Where(vm => vm is IPageViewModel) .Select(vm => (IPageViewModel)vm) .Subscribe(page => { page.WhenAnyValue(p => p.Title).BindTo(this, t => t.Title); page.WhenAnyValue(p => p.IsBusy).BindTo(this, t => t.IsBusy); }); Router.CurrentViewModel .Select(vm => vm is NewProjectViewModel) .ToProperty(this, t => t.IsNewProjectPageVisible, out _isNewProjectPageVisible); Router.CurrentViewModel .Select(vm => vm is AboutViewModel) .ToProperty(this, t => t.IsAboutPageVisible, out _isAboutPageVisible); }
public NewProjectViewModel(IScreen hostScreen) : base("newprj", hostScreen) { var configureAppModel = new ConfigureAppViewModel(this); Router.Navigate.Execute(configureAppModel); OpenSetupWizard = ReactiveCommand.CreateFromObservable <Unit, Unit>(sender => { return(ShowSetupWizard.Handle(Unit.Default)); }); IObservable <WizardPageViewModel> pageObservable = Router.CurrentViewModel .Where(vm => vm is WizardPageViewModel) .Select(vm => vm as WizardPageViewModel); pageObservable.Select(p => p.Title).BindTo(this, t => t.Title); pageObservable.Select(p => p.Description).BindTo(this, t => t.Description); pageObservable.Select(p => p.IsDescriptionVisible).BindTo(this, t => t.IsDescriptionVisible); pageObservable.Subscribe(p => p.WhenAnyValue(page => page.IsBusy).BindTo(this, t => t.IsBusy)); pageObservable.Select(p => p.NextText).ToProperty(this, t => t.NextText, out _nextText); pageObservable.Select(p => p.BackText).ToProperty(this, t => t.BackText, out _backText); pageObservable.Select(p => p.BackVisible).ToProperty(this, t => t.HasBack, out _hasBack); pageObservable .Select(p => { ReactiveCommand <Unit, Unit> cmdDoSomething = ReactiveCommand.CreateFromTask(p.OnNext, outputScheduler: RxApp.MainThreadScheduler); ReactiveCommand <Unit, Unit> cmdNavigateOrClose; if (p.IsFinishPage) { cmdNavigateOrClose = ReactiveCommand.CreateFromTask(async() => { await cmdDoSomething.Execute(); await Router.NavigateAndReset.Execute(new ConfigureAppViewModel(this)); }, canExecute: p.WhenAnyValue(page => page.NextEnabled), outputScheduler: RxApp.MainThreadScheduler); } else { cmdNavigateOrClose = ReactiveCommand.CreateFromTask(async() => { await cmdDoSomething.Execute(); await Router.Navigate.Execute(p.GetNextPage()); }, canExecute: p.WhenAnyValue(page => page.NextEnabled), outputScheduler: RxApp.MainThreadScheduler); } cmdNavigateOrClose .ThrownExceptions //.FirstAsync() .Throttle(TimeSpan.FromMilliseconds(250), RxApp.MainThreadScheduler) .Subscribe(async ex => { await ShowError.Handle(ex); }); return(cmdNavigateOrClose); }) .ToProperty(this, t => t.GoNext, out _goNext); this.WhenActivated(disposables => { if (Router.NavigationStack.Count > 0) { IRoutableViewModel fistPage = Router.NavigationStack[0]; Router.NavigateAndReset.Execute(fistPage); Router.NavigateAndReset.Execute(fistPage).Subscribe().DisposeWith(disposables); } //else //{ // Router.Navigate.Execute(new ConfigureAppViewModel(this)).Subscribe().DisposeWith(disposables); //} }); }