private void startApplication() { // Load and show the MainWindow MainWindow main = new MainWindow(); Navigator.NavigationService = main.NavigationFrame.NavigationService; //MainWindowViewModel has to be initialized after navigationService is set otherwise the //MainWindowViewModel tries to use an instance of NavigationService per the PageNavigation class //before it is initialized and returns a null reference to navigationservice MainWindowViewModel vm = new MainWindowViewModel(); main.DataContext = vm; main.Show(); }
public void NavigatePage(string _pageName) { _navigationStack.Add(_pageName); MessageBox.Show("added " + _pageName + " to stack"); CurrentPage = _pageName; switch (_pageName) { case "Main": if (Main == null) { MainVM = new MainWindowViewModel(); Main = new MainWindow(); } Main.DataContext = MainVM; Navigator.NavigationService.Navigate(Main); break; case "Home": if (Home == null) { HomeVM = new HomeViewModel(); Home = new Home(); } Home.DataContext = HomeVM; Navigator.NavigationService.Navigate(Home); break; case "MOVIES": if (MOVIES == null) { MediaVM = new MediaViewModel(_pageName); MOVIES = new Media(); } MOVIES.DataContext = MediaVM; Navigator.NavigationService.Navigate(MOVIES); break; case "TV SHOWS": if (TV == null) { TVVM = new MediaViewModel(_pageName); TV = new Media(); } TV.DataContext = TVVM; Navigator.NavigationService.Navigate(TV); break; } }