// Extension Methods // *** Navigation *** #region public static void Navigate(this IRoutingState router, IRoutableViewModel viewModel, IRoutingParams routingParams) /// <summary> /// Navigates the specified router. /// </summary> /// <param name="router">The router.</param> /// <param name="viewModel">The view model.</param> /// <param name="routingParams">The routing parameters.</param> public static void Navigate(this IRoutingState router, IRoutableViewModel viewModel, IRoutingParams routingParams) { if (router != null) { router.Navigate.Execute(new RoutableViewModelWithParams(viewModel, routingParams)); } }
public void AppStateShouldBeSetOnRepairClicked() { var router = new RoutingState(); var kernel = new NSubstituteMockingKernel(); IRoutableViewModel latestVm = null; var fixture = setupStandardFixture(router, kernel, () => { var branchInfo = new Dictionary <string, HeuristicTreeInformation>() { { "Working Directory", new HeuristicTreeInformation("derp", true) } }; kernel.Get <IRepoAnalysisProvider>().AnalyzeRepo(null) .ReturnsForAnyArgs(Observable.Return(Tuple.Create("foo", branchInfo))); router.ViewModelObservable().Subscribe(x => latestVm = x); }); fixture.AnalyzeRepo.Execute("foo"); fixture.RepairButtonVisibility.ShouldEqual(Visibility.Visible); fixture.RepairButton.Execute(null); var result = kernel.Get <IAppState>(); (latestVm is IRepairViewModel).ShouldBeTrue(); result.CurrentRepo.ShouldEqual("foo"); result.BranchInformation.ShouldNotBeNull(); }
protected IObservable <Page> PageForViewModel(IRoutableViewModel vm) { if (vm == null) { return(Observable.Empty <Page>()); } var ret = ViewLocator.Current.ResolveView(vm); if (ret == null) { var msg = String.Format( "Couldn't find a View for ViewModel. You probably need to register an IViewFor<{0}>", vm.GetType().Name); return(Observable.Throw <Page>(new Exception(msg))); } ret.ViewModel = vm; var pg = (Page)ret; pg.Title = vm.UrlPathSegment; return(Observable.Return(pg)); }
public dummyScreen() { Router = new RoutingState(); Router.CurrentViewModel .Subscribe(vm => CurrentVM = vm); }
/// <summary> /// Navigates the specified router. /// </summary> /// <param name="router">The router.</param> /// <param name="viewModel">The view model.</param> /// <param name="notInNavigationStack">if set to <c>true</c> [not in navigation stack].</param> public static void Navigate(this IRoutingState router, IRoutableViewModel viewModel, bool notInNavigationStack) { router.Navigate(viewModel, new RoutingParams { NotInNavigationStack = notInNavigationStack }); }
public static IObservable <Unit> NavigatedToMe(this IRoutableViewModel This) { return(Observable.Create <Unit>(subj => { return This.HostScreen.Router.CurrentViewModel .Where(x => x == This) .Select(_ => Unit.Default) .Subscribe(subj); })); }
/// <summary> /// This method will return an observable that fires events every time /// the topmost ViewModel in the navigation stack is this ViewModel. /// This allows you to set up connections that only operate while the /// ViewModel has focus. /// /// The observable will complete when the ViewModel is removed completely /// from the navigation stack. If your ViewModel can be _removed_ from /// the navigation stack and then reused later, you must call this method /// and resubscribe each time it is reused. /// </summary> /// <param name="this">The viewmodel to watch for navigation changes</param> /// <returns>An IObservable{Unit} that signals when the ViewModel has /// been added or brought to the top of the navigation stack. The /// observable completes when the ViewModel is no longer a part of the /// navigation stack.</returns> public static IObservable <Unit> WhenNavigatedToObservable(this IRoutableViewModel @this) { var router = @this.HostScreen.Router; var navigationStackChanged = router.NavigationChanged.CountChanged(); var itemRemoved = navigationStackChanged .Where(x => x.Any(change => change.Reason == ListChangeReason.Remove && change.Item.Current == @this)); return(navigationStackChanged .Where(_ => router.GetCurrentViewModel() == @this) .Select(_ => Unit.Default) .TakeUntil(itemRemoved)); }
/// <summary> /// This method will return an observable that fires events _just before_ /// the ViewModel is no longer the topmost ViewModel in the navigation /// stack. This allows you to clean up anything before losing focus. /// /// The observable will complete when the ViewModel is removed completely /// from the navigation stack. If your ViewModel can be _removed_ from /// the navigation stack and then reused later, you must call this method /// and resubscribe each time it is reused. /// </summary> /// /// <param name="this">The viewmodel to watch for navigation changes</param> /// <returns>An IObservable{Unit} that signals when the ViewModel is no /// longer the topmost ViewModel in the navigation stack. The observable /// completes when the ViewModel is no longer a part of the navigation /// stack.</returns> public static IObservable <Unit> WhenNavigatingFromObservable(this IRoutableViewModel @this) { var router = @this.HostScreen.Router; var navigationStackChanged = router.NavigationChanged.CountChanged(); var itemRemoved = navigationStackChanged .Where(x => x.Any(change => change.Reason == ListChangeReason.Remove && change.Item.Current == @this)); var viewModelsChanged = navigationStackChanged.Scan(new IRoutableViewModel[2], (previous, current) => new[] { previous[1], router.GetCurrentViewModel() }); return(viewModelsChanged .Where(x => x[0] == @this) .Select(_ => Unit.Default) .TakeUntil(itemRemoved)); }
/// <summary> /// 导航至页面 /// </summary> /// <param name="vModel"></param> private void NavigateTo(string urlPathSegment) { IRoutableViewModel vm = null; if (this.m_VModelDict.ContainsKey(urlPathSegment)) { vm = this.m_VModelDict[urlPathSegment]; } else { if (urlPathSegment.Equals(nameof(ChatViewModel))) { vm = Locator.CurrentMutable.GetService <ChatViewModel>(); } else if (urlPathSegment.Equals(nameof(GroupViewModel))) { vm = Locator.CurrentMutable.GetService <GroupViewModel>(); } else if (urlPathSegment.Equals(nameof(ContactsViewModel))) { vm = Locator.CurrentMutable.GetService <ContactsViewModel>(); } else if (urlPathSegment.Equals(nameof(SearchViewModel))) { vm = Locator.CurrentMutable.GetService <SearchViewModel>(); } else if (urlPathSegment.Equals(nameof(SettingViewModel))) { vm = Locator.CurrentMutable.GetService <SettingViewModel>(); } else if (urlPathSegment.Equals(nameof(ProfileViewModel))) { vm = Locator.CurrentMutable.GetService <ProfileViewModel>(); } else if (urlPathSegment.Equals(nameof(WelcomeViewModel))) { vm = Locator.CurrentMutable.GetService <WelcomeViewModel>(); } else { return; } this.m_VModelDict.Add(urlPathSegment, vm); } SubRouter.Navigate.Execute(vm); }
IObservable<Page> pageForViewModel(IRoutableViewModel vm) { if (vm == null) return Observable.Empty<Page>(); var ret = ViewLocator.Current.ResolveView(vm); if (ret == null) { var msg = String.Format( "Couldn't find a View for ViewModel. You probably need to register an IViewFor<{0}>", vm.GetType().Name); return Observable.Throw<Page>(new Exception(msg)); } ret.ViewModel = vm; var pg = (Page)ret; pg.Title = vm.UrlPathSegment; return Observable.Return(pg); }
public void NavigateToPage(IRoutableViewModel routableViewModel, bool cleanNavigationStack = false) { if (cleanNavigationStack) { HostScreen .Router .NavigateAndReset .Execute(routableViewModel) .Subscribe(); } else { HostScreen .Router .Navigate .Execute(routableViewModel) .Subscribe(); } }
/// <summary> /// Navigates the specified view model. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="notInNavigationStack">if set to <c>true</c> [not in navigation stack].</param> /// <exception cref="System.NotImplementedException"></exception> public void Navigate(IRoutableViewModel viewModel, bool notInNavigationStack = false) { var viewModelWithParams = viewModel as IRoutableViewModelWithParams; if (viewModelWithParams != null) { if (viewModelWithParams.RoutingParams != null) { viewModelWithParams.RoutingParams.NotInNavigationStack = notInNavigationStack; } else { viewModelWithParams.RoutingParams = new RoutingParams { NotInNavigationStack = notInNavigationStack }; } AppModel.Router.Navigate(viewModelWithParams.RoutableViewModel, viewModelWithParams.RoutingParams); } else { AppModel.Router.Navigate(viewModel, notInNavigationStack); } }
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); //} }); }
protected IObservable <IRoutableViewModel> NavigateTo(IRoutableViewModel viewModel) => HostScreen.Router.Navigate.Execute(viewModel);
public static IObservable <IRoutableViewModel> NavigateToView(this IScreen s, IRoutableViewModel viewModel) => s.Router.Navigate.Execute(viewModel);
public static IObservable <Unit> NavigateBack(this IRoutableViewModel r) => r.HostScreen.Router.NavigateBack.Execute();
public static IObservable <IRoutableViewModel> NavigateToView(this IRoutableViewModel r, IRoutableViewModel viewModel) => r.HostScreen.Router.Navigate.Execute(viewModel);
/// <summary> /// Navigates the specified view model. /// </summary> /// <param name="viewModel">The view model.</param> /// <param name="routingParams">The routing parameters.</param> /// <exception cref="System.NotImplementedException"></exception> public void Navigate(IRoutableViewModel viewModel, IRoutingParams routingParams) { AppModel.Router.Navigate(viewModel, routingParams); }
private UIViewController ResolveView (IRoutableViewModel viewModel, string contract) { if (viewModel == null) { return null; } var viewLocator = this.ViewLocator ?? ReactiveUI.ViewLocator.Current; var view = viewLocator.ResolveView (viewModel, contract); if (view == null) { throw new Exception ( string.Format ( "Couldn't find a view for view model. You probably need to register an IViewFor<{0}>", viewModel.GetType ().Name)); } view.ViewModel = viewModel; var viewController = view as UIViewController; if (viewController == null) { throw new Exception ( string.Format ( "View type {0} for view model type {1} is not a UIViewController", view.GetType ().Name, viewModel.GetType ().Name)); } return viewController; }
public void Post(IRoutableViewModel viewModel) { show.OnNext(viewModel); }
/// <summary> /// Navigates the specified router. /// </summary> /// <param name="router">The router.</param> /// <param name="viewModel">The view model.</param> /// <param name="notInNavigationStack">if set to <c>true</c> [not in navigation stack].</param> /// <param name="reuseExistingView">if set to <c>true</c> [reuse existing view].</param> public static void Navigate(this IRoutingState router, IRoutableViewModel viewModel, bool notInNavigationStack, bool reuseExistingView) { router.Navigate(viewModel, new CustomRoutingParams { NotInNavigationStack = notInNavigationStack, ReuseExistingView = reuseExistingView }); }
public SetupWindowViewModel() { IObservable <IAdvancedWizardPageViewModel> pageObservable = Router.CurrentViewModel .Where(vm => vm is IAdvancedWizardPageViewModel) .Select(vm => vm as IAdvancedWizardPageViewModel); pageObservable.Select(p => p.Title).BindTo(this, t => t.Title); pageObservable.Subscribe(p => p.WhenAnyValue(page => page.IsBusy).BindTo(this, t => t.IsBusy)); pageObservable.Select(p => p.Button1Text).ToProperty(this, t => t.Button1Text, out _button1Text); pageObservable.Select(p => p.Button2Text).ToProperty(this, t => t.Button2Text, out _button2Text); pageObservable.Select(p => p.Button3Text).ToProperty(this, t => t.Button3Text, out _button3Text); pageObservable.Select(p => p.Button1Visible).ToProperty(this, t => t.HasButton1, out _hasButton1); pageObservable.Select(p => p.Button2Visible).ToProperty(this, t => t.HasButton2, out _hasButton2); pageObservable.Select(p => p.Button3Visible).ToProperty(this, t => t.HasButton3, out _hasButton3); //pageObservable.Select(p => p.Button3Enabled).ToProperty(this, t => t.Button3Enabled, out _button3Enabled); pageObservable.Subscribe(p => p.WhenAnyValue(page => page.Button3Enabled).BindTo(this, t => t.Button3Enabled)); pageObservable.Select(p => p.Button1Command).ToProperty(this, t => t.Button1Command, out _button1Command); pageObservable.Select(p => p.Button2Command).ToProperty(this, t => t.Button2Command, out _button2Command); pageObservable.Select(p => p.Button3Command).ToProperty(this, t => t.Button3Command, out _button3Command); //TODO /* * * * 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 SetupWelcomeViewModel(this)).Subscribe().DisposeWith(disposables); } }); }
public void Navigate(IRoutableViewModel viewModel) { HostScreen.Router.Navigate.Execute(viewModel); }
/// <summary> /// Navigate to a specific page /// </summary> /// <param name="model"></param> void navigateTo(IRoutableViewModel model) { Router.Navigate.Execute(model); }