Пример #1
0
        /// <summary>
        /// Initialises the view model, user interface and data binding from the view model
        /// to the interface.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            generationViewModel = new GenerationViewModel(
                ConwaysGameOfLife.Properties.Settings.Default.UniverseSize
            );

            BuildGridUI(generationViewModel);

            DataContext = generationViewModel;
        }
Пример #2
0
        /// <summary>
        /// Builds the game of life user interface.
        /// </summary>
        /// <param name="generationViewModel">Generation view model.</param>
        private void BuildGridUI(GenerationViewModel generationViewModel)
        {
            for (int row = 0; row < generationViewModel.UniverseSize; row++)
            {
                UniverseGrid.RowDefinitions.Add(new RowDefinition());

                for (int column = 0; column < generationViewModel.UniverseSize; column++)
                {
                    if (row == 0)
                        UniverseGrid.ColumnDefinitions.Add(new ColumnDefinition());

                    // Let's use a TextBlock to visually represent a cell
                    TextBlock cellTextBlock = CreateCellTextBlock(generationViewModel.GetCell(row, column));

                    // Position the "cell" in the grid
                    Grid.SetRow(cellTextBlock, row);
                    Grid.SetColumn(cellTextBlock, column);

                    UniverseGrid.Children.Add(cellTextBlock);
                }
            }
        }