private void InstanceOnNavigationRequested(INavigationRequest navigationRequest) { if (navigationRequest is PushCategoriesPage) { Navigation.PushAsync(new CategoriesPage(), true); } else if (navigationRequest is PushMoneySpentSumPage) { Navigation.PushAsync(new MoneySpentSumPage(), true); } else if (navigationRequest is BackToWelcomePage) { Navigation.PopToRootAsync(); } else if (navigationRequest is MainMenuWelcome) { ReplaceRoot(new WelcomePage()); } else if (navigationRequest is MainMenuCategories) { ReplaceRoot(new CategoriesSummaryPage()); } else if (navigationRequest is MainMenuSettings) { ReplaceRoot(new SettingsPage()); } else if (navigationRequest is MainMenuStatement) { ReplaceRoot(new StatementPage()); } }
public async Task Navigate(CancellationToken ct, INavigationRequest request) { await _innerRequestNavigation.Navigate(ct, request); var firstEntry = _applicationFrame.BackStack.FirstOrDefault(); if (firstEntry != null && firstEntry.Source.Equals(_entryPointUri)) { await _dispatcherScheduler.Run(() => _applicationFrame.RemoveBackEntry()); } }
public void InsertRequest(int index, INavigationRequest request) { if (request == null) throw new ArgumentNullException("request"); if (index > _entries.Count - 1) { throw new ArgumentOutOfRangeException("index"); } _entries.Insert(index, new NotAliveNavigationHistoryEntry(request)); }
public async Task Navigate(CancellationToken ct, INavigationRequest request) { await _innerRequestNavigation.Navigate(ct, request); var firstEntry = _applicationFrame.BackStack.FirstOrDefault(); if (firstEntry != null && firstEntry.Source.Equals(_entryPointUri)) { await _dispatcherScheduler.Run(() => _applicationFrame.RemoveBackEntry()); } }
public void InsertRequest(int index, INavigationRequest request) { if (request == null) { throw new ArgumentNullException("request"); } if (index > _entries.Count - 1) { throw new ArgumentOutOfRangeException("index"); } _entries.Insert(index, new NotAliveNavigationHistoryEntry(request)); }
public void Initialize(INavigationRequest navigationRequest) { if (navigationRequest == null) { throw new ArgumentNullException("navigationRequest"); } NavigationRequest = navigationRequest; foreach (var viewModel in _children) { viewModel.Initialize(navigationRequest); } DefineRules(); OnInitialized(); }
public void Register_WhenAlreadyInitialized_ShouldCallChildrenInitialize( TestViewModel sut, Mock <ViewModelBase> child, INavigationRequest request) { //arrange child.As <IViewModel>(); sut.Initialize(request); //act sut.CallRegisterChild(child.Object); //assert child.As <IViewModel>().Verify(c => c.Initialize(request), Times.Once()); }
public async Task Navigate(CancellationToken ct, INavigationRequest request) { ct = CancellationToken.None; await Task.Run(async() => { var isReleased = false; await _semaphore.WaitAsync(ct); try { var pageDefinition = _pageDefinitions.GetPageDefinition(request.PageName); var viewModel = _viewModelFactory.ResolveViewModel(pageDefinition.ViewModelType); viewModel.Initialize(request); //create tasks var setDataContext = SetPageDataContext(pageDefinition, viewModel).ToTask(ct); var navigatingTask = NotifyNavigating(ct, pageDefinition, request); var navigationIsStarted = await _dispatcherScheduler.Run(() => _frame.Navigate(pageDefinition.PageType)); if (!navigationIsStarted) { throw new InvalidOperationException("Navigation failed"); } await navigatingTask; var pageElement = await setDataContext; //since the navigation completed, we can let another navigation start _semaphore.Release(); isReleased = true; //add entry to history var historyEntry = new AliveNavigationHistoryEntry(request, viewModel); _history.Append(historyEntry); //list to loaded / unloaded events RegisterViewModelLoad(pageElement, viewModel); RegisterViewModelUnload(pageElement, viewModel); _navigatedSubject.OnNext(request); } finally { if (!isReleased) { _semaphore.Release(); isReleased = true; } } }); }
public async Task Navigate(CancellationToken ct, INavigationRequest request) { SettingsFlyoutDefinition definition; if (!_definitions.TryGetValue(request.PageName, out definition)) { await _inner.Navigate(ct, request); return; } var viewModel = _viewModelFactory.ResolveViewModel(definition.ViewModelType); viewModel.Initialize(request); await _dispatcher.Run(() => { var flyout = (SettingsFlyout)Activator.CreateInstance(definition.FlyoutType); flyout.DataContext = viewModel; flyout.Unloaded += (sender, args) => _viewModelFactory.ReleaseViewModel(viewModel); flyout.Show(); }); await viewModel.Load(ct); }
private Task NotifyNavigating(CancellationToken ct, PageDefinition pageDefinition, INavigationRequest request) { return Observable.FromEventPattern<NavigatingCancelEventHandler, NavigatingCancelEventArgs>(h => _frame.Navigating += h, h => _frame.Navigating -= h) .SubscribeOn(_dispatcherScheduler) .Where(args => args.EventArgs.Uri == pageDefinition.Uri && args.EventArgs.NavigationMode == NavigationMode.New) .Do(_ => _navigatingSubject.OnNext(request)) .Take(1) .SelectUnit() .ToTask(ct); }
public NotAliveNavigationHistoryEntry(INavigationRequest request) { Request = request; }
public Task Navigate(CancellationToken ct, INavigationRequest request) { return Task.FromResult(true); }
public void Register_WhenAlreadyInitialized_ShouldCallChildrenInitialize( TestViewModel sut, Mock<ViewModelBase> child, INavigationRequest request) { //arrange child.As<IViewModel>(); sut.Initialize(request); //act sut.CallRegisterChild(child.Object); //assert child.As<IViewModel>().Verify(c => c.Initialize(request), Times.Once()); }
public void Request(INavigationRequest pushCategoriesPage) { System.Diagnostics.Debug.WriteLine("Hey, we inside navigation service !!!!2"); NavigationRequested?.Invoke(pushCategoriesPage); }
private Task NotifyNavigating(CancellationToken ct, PageDefinition pageDefinition, INavigationRequest request) { return(Observable.FromEventPattern <NavigatingCancelEventHandler, NavigatingCancelEventArgs>(h => _frame.Navigating += h, h => _frame.Navigating -= h) .SubscribeOn(_dispatcherScheduler) .Where(args => args.EventArgs.Uri == pageDefinition.Uri && args.EventArgs.NavigationMode == NavigationMode.New) .Do(_ => _navigatingSubject.OnNext(request)) .Take(1) .SelectUnit() .ToTask(ct)); }
public NotAliveNavigationHistoryEntry(INavigationRequest request) { Request = request; }
public AliveNavigationHistoryEntry(INavigationRequest request, IViewModel viewModel) { ViewModel = viewModel; Request = request; }
public AliveNavigationHistoryEntry(INavigationRequest request, IViewModel viewModel) { ViewModel = viewModel; Request = request; }
public async Task Navigate(CancellationToken ct, INavigationRequest request) { await Task.Run(async () => { var isReleased = false; await _semaphore.WaitAsync(); try { var pageDefinition = _pageDefinitions.GetPageDefinition(request.PageName); var viewModel = _viewModelFactory.ResolveViewModel(pageDefinition.ViewModelType); //create tasks var setDataContext = SetPageDataContext(pageDefinition, viewModel).ToTask(); var navigatingTask = NotifyNavigating(ct, pageDefinition, request); var navigationIsStarted = await _dispatcherScheduler.Run(() => _frame.Navigate(pageDefinition.Uri)); if (!navigationIsStarted) { throw new InvalidOperationException("Navigation failed"); } viewModel.Initialize(request); await navigatingTask; var pageElement = await setDataContext; //since the navigation completed, we can let another navigation start _semaphore.Release(); isReleased = true; //add entry to history var historyEntry = new AliveNavigationHistoryEntry(request, viewModel); _history.Append(historyEntry); //list to loaded / unloaded events RegisterViewModelLoad(pageElement, viewModel); RegisterViewModelUnload(pageElement, viewModel); } finally { if (!isReleased) { _semaphore.Release(); isReleased = true; } } }); }