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>
        /// Method used for the Executed part of the command bindings defined in the window.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Close)
            {
                this.Close();
            }
            if (e.Command == GameViewModel.StartGameCommand)
            {
                var model = new GameViewModel();

                // Instantiate the start game dialog.
                StartGame startGameDialog = new StartGame();

                // Load the game options, and set them as the data context for the start game window.
                var options = GameOptions.Create();
                startGameDialog.DataContext = options;

                // Display the start game dialog.
                var result = startGameDialog.ShowDialog();
                if (result.HasValue && result.Value == true)
                {
                    // The user clicked OK on the start game dialog, so save the options, tell the
                    // model to start a new game, and set the model as the data context for the game
                    // client window.
                    options.Save();
                    model.StartNewGame();
                    DataContext = model;
                }
            }
            if (e.Command == GameOptions.OptionsCommand)
            {
                // Instantiate and display the options window.
                var dialog = new Options();
                var result = dialog.ShowDialog();

                // If the user clicked OK in the options dialog, clear the current game.
                if (result.HasValue && result.Value == true)
                {
                    DataContext = new GameViewModel();
                }
            }
            if (e.Command == GameViewModel.ShowAboutCommand)
            {
                // Instantiate and display the about dialog.
                var dialog = new About();
                dialog.ShowDialog();
            }
            e.Handled = true;
        }
Exemplo n.º 3
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;
 }