public void Navigate(NavigateTypes navigateTypes, object context = null) { ViewModelBase viewModel = null; switch (navigateTypes) { case NavigateTypes.Back: if (_History.Count > 0) { viewModel = _History.Pop(); } if (viewModel == null) { viewModel = _ProfessionsViewModel; } break; case NavigateTypes.Help: if (_HelpViewModel == null) { _HelpViewModel = new HelpViewModel(); } viewModel = _HelpViewModel; if (_CurrentViewModel != null) { _History.Push(_CurrentViewModel); } break; case NavigateTypes.Error: var exception = (Exception)context; viewModel = new ErrorViewModel(exception); break; case NavigateTypes.Profession: var professionName = (string)context; ProfessionViewModel professionViewModel; if (!_ProfessionViewModels.TryGetValue(professionName, out professionViewModel)) { var profession = BulkOrderDeedManager.Instance.Professions.FirstOrDefault(p => String.Compare(professionName, p.Name, true) == 0); if (profession != null) { professionViewModel = new ProfessionViewModel(profession); _ProfessionViewModels[professionName] = professionViewModel; viewModel = professionViewModel; } } else { viewModel = professionViewModel; } if (viewModel != null && _CurrentViewModel != null) { _History.Push(_CurrentViewModel); } break; case NavigateTypes.BulkOrderDeedsForReward: var professionRewardSearchCriteria = (ProfessionRewardSearchCriteria)context; BulkOrderDeedsForRewardViewModel bulkOrderDeedsForRewardViewModel; if (!_BulkOrderDeedsForRewardViewModels.TryGetValue(professionRewardSearchCriteria, out bulkOrderDeedsForRewardViewModel)) { bulkOrderDeedsForRewardViewModel = new BulkOrderDeedsForRewardViewModel(professionRewardSearchCriteria); _BulkOrderDeedsForRewardViewModels[professionRewardSearchCriteria] = bulkOrderDeedsForRewardViewModel; } viewModel = bulkOrderDeedsForRewardViewModel; if (viewModel != null && _CurrentViewModel != null) { _History.Push(_CurrentViewModel); } break; case NavigateTypes.BulkOrderDeedCollection: if (_CollectionViewModel == null) { _CollectionViewModel = new CollectionViewModel(); } _CollectionViewModel.RefreshIfNecessary(); viewModel = _CollectionViewModel; if (_CurrentViewModel != null) { _History.Push(_CurrentViewModel); } break; case NavigateTypes.AddBulkOrderDeedToCollection: var collectionBulkOrderDeed = (CollectionBulkOrderDeed)context; viewModel = new AddBulkOrderDeedToCollectionViewModel(collectionBulkOrderDeed); if (_CurrentViewModel != null) { _History.Push(_CurrentViewModel); } break; default: case NavigateTypes.Professions: try { if (_ProfessionsViewModel == null) { _ProfessionsViewModel = new ProfessionsViewModel(); } viewModel = _ProfessionsViewModel; } catch (Exception ex) { Navigate(NavigateTypes.Error, ex); } _History.Clear(); break; } if (viewModel != null) { _CurrentViewModel = viewModel; App.Current.MainWindow.DataContext = _CurrentViewModel; } }