Beispiel #1
0
        public SudokuViewModel(Grid sudokuGrid, ISudokuGameModel sudokuGame)
        {
            // grid form the program
            SudokuGrid = sudokuGrid;

            // prepare model
            SudokuGame = sudokuGame;

            // prepare game grid (view)
            SudokuBoardView = new SudokuBoardUserControl();

            // add game grid to program
            sudokuGrid.Children.Add(SudokuBoardView.GetUIElement());
            Grid.SetRow(SudokuBoardView.GetUIElement(), 0);
            Grid.SetColumn(SudokuBoardView.GetUIElement(), 0);

            // prepare the binding
            for (int row = 0; row < 9; row++)
            {
                for (int column = 0; column < 9; column++)
                {
                    GameCellToViewCell[row, column] = new CellViewModel();
                }
            }

            // prepare Key operation
            SudokuBoardView.SetKeyEventHandler(KeyUp);

            // create the game button user control (view)
            SudokuCommands = new SudokuCommandUserControl();

            // add command panel to program
            sudokuGrid.Children.Add(SudokuCommands.GetUIElement());
            Grid.SetRow(SudokuCommands.GetUIElement(), 0);
            Grid.SetColumn(SudokuCommands.GetUIElement(), 1);

            // bind command to buttons
            SudokuCommands.SetCommandEventHandler(SudokuCommand.Clear, ClearCommand);
            SudokuCommands.SetCommandEventHandler(SudokuCommand.Back, BackCommand);
            SudokuCommands.SetCommandEventHandler(SudokuCommand.New, NewCommand);
            SudokuCommands.SetCommandEventHandler(SudokuCommand.Solve, SolveCommand);
            SudokuCommands.SetCommandEventHandler(SudokuCommand.TogglePossibleValues, TogglePossibleValuesVisibilityCommand);

            SudokuBoardView.MarkCell(0, 0);
            UpdateValues();
        }
 public static void InitializeViewModels(Grid grid)
 {
     _sudokuGame      = new SudokuGame("Game");
     _sudokuViewModel = new SudokuViewModel(grid, _sudokuGame);
 }