Exemplo n.º 1
0
 private void CommandExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     if (e.Command == ApplicationCommands.Close)
     this.Close();
       if (e.Command == GameViewModel.StartGameCommand)
       {
     var model = new GameViewModel();
     StartGame startGameDialog = new StartGame();
     var options = GameOptions.Create();
     startGameDialog.DataContext = options;
     var result = startGameDialog.ShowDialog();
     if (result.HasValue && result.Value == true)
     {
       options.Save();
       model.StartNewGame();
       DataContext = model;
     }
       }
       if (e.Command == GameOptions.OptionsCommand)
       {
     var dialog = new Options();
     var result = dialog.ShowDialog();
     if (result.HasValue && result.Value == true)
       DataContext = new GameViewModel(); // Clear current game
       }
       if (e.Command == GameViewModel.ShowAboutCommand)
       {
     var dialog = new About();
     dialog.ShowDialog();
       }
       e.Handled = true;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Populates the page with content passed during navigation.  Any saved state is also
 /// provided when recreating a page from a prior session.
 /// </summary>
 /// <param name="navigationParameter">The parameter value passed to
 /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
 /// </param>
 /// <param name="pageState">A dictionary of state preserved by this page during an earlier
 /// session.  This will be null the first time a page is visited.</param>
 protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
 {
     if (pageState != null && pageState["CurrentGame"] != null)
       {
     var context = pageState["CurrentGame"] as GameViewModel;
     if (context != null)
     {
       this.DataContext = context;
       context.ContinueGame();
     }
       }
       else if (navigationParameter != null)
       {
     var players = navigationParameter as string;
     var newGame = new GameViewModel();
     newGame.StartNewGame(PlayerNames.FromString(players));
     DataContext = newGame;
       }
 }