/// <summary>
        /// The window changed size.
        /// </summary>
        /// <param name="sender">The sending object.</param>
        /// <param name="e">The event.</param>
        private void Window_SizeChanged_1(object sender, SizeChangedEventArgs e)
        {
            // Clear out any previous animation
            StopAnimation();
            CanvasOutput.Children.Clear();

            // Create new animation at correct size.
            _display = new UniverseDisplayCell((int)e.NewSize.Width, (int)e.NewSize.Height, null);
            _display.UniverseRunner.PhysicsRules.CopyData(_physics);
            _display.Visualize();
            _display.UniverseRunner.AutoKill = false;
            var img = new Image {
                Source = _display.Image
            };

            img.SetValue(Canvas.LeftProperty, 0.0);
            img.SetValue(Canvas.TopProperty, 0.0);
            CanvasOutput.Children.Add(img);

            // Start the thread.
            _stopRequest = false;
            _background  = new Thread(DoWork);
            _background.Start();
        }
        /// <summary>
        /// The window changed size.
        /// </summary>
        /// <param name="sender">The sending object.</param>
        /// <param name="e">The event.</param>
        private void Window_SizeChanged_1(object sender, SizeChangedEventArgs e)
        {
            // Clear out any previous animation
            StopAnimation();
            CanvasOutput.Children.Clear();

            // Create new animation at correct size.
            _display = new UniverseDisplayCell((int) e.NewSize.Width, (int) e.NewSize.Height, null);
            _display.UniverseRunner.PhysicsRules.CopyData(_physics);
            _display.Visualize();
            _display.UniverseRunner.AutoKill = false;
            var img = new Image {Source = _display.Image};
            img.SetValue(Canvas.LeftProperty, 0.0);
            img.SetValue(Canvas.TopProperty, 0.0);
            CanvasOutput.Children.Add(img);

            // Start the thread.
            _stopRequest = false;
            _background = new Thread(DoWork);
            _background.Start();
        }
        /// <summary>
        /// The mouse was pressed.
        /// </summary>
        /// <param name="sender">The sending object.</param>
        /// <param name="e">The event.</param>
        private void CanvasOutput_MouseDown(object sender, MouseButtonEventArgs e)
        {
            // update selected cell
            Point pt = Mouse.GetPosition(CanvasOutput);

            int univWidth = Settings.Default.PaneWidth;
            int univHeight = Settings.Default.PaneHeight;

            _selectedRow = (int) (pt.Y/univWidth);
            _selectedCol = (int) (pt.X/univHeight);

            _selectedCell = _multiverse[_selectedRow][_selectedCol];

            // if left-click then perform correct operation (if any)
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (_copySource != null)
                {
                    UniverseRunner target = _selectedCell
                        .UniverseRunner;
                    target.PhysicsRules.CopyData(
                        _copySource.PhysicsRules.Data);
                    target.Randomize(_rnd);
                }
                else if (_crossoverParent1 != null
                         && _crossoverParent2 == null)
                {
                    _crossoverParent2 = _selectedCell.UniverseRunner;
                }
                else
                {
                    UniverseRunner target = _selectedCell.UniverseRunner;
                    target.Crossover(_rnd, _crossoverParent1, _crossoverParent2);
                    target.Randomize(_rnd);
                }
            }
        }
        /// <summary>
        /// Setup after the window loads.
        /// </summary>
        /// <param name="sender">The sending object.</param>
        /// <param name="e">The event.</param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            double univWidth = Settings.Default.PaneWidth;
            double univHeight = Settings.Default.PaneHeight;

            CheckAutoKill.IsChecked = true;

            _multiverse = new UniverseDisplayCell[Settings.Default.UniversePaneRows][];
            for (int row = 0; row < Settings.Default.UniversePaneRows; row++)
            {
                _multiverse[row] = new UniverseDisplayCell[Settings.Default.UniversePaneColumns];
                for (int col = 0; col < Settings.Default.UniversePaneColumns; col++)
                {
                    double x = col*univWidth;
                    double y = row*univHeight;

                    // Label
                    var lab = new Label
                    {
                        Foreground = Brushes.Black,
                        Background = Brushes.LightGray,
                        FontSize = 10,
                        Content = "..."
                    };
                    lab.SetValue(Canvas.LeftProperty, x);
                    lab.SetValue(Canvas.TopProperty, y);

                    // Universe image.
                    int paneWidth = Settings.Default.PaneWidth;
                    int paneHeight = Settings.Default.PaneHeight;
                    _multiverse[row][col] = new UniverseDisplayCell(paneWidth, paneHeight, lab);
                    _multiverse[row][col].UniverseRunner.Randomize(new MersenneTwisterGenerateRandom());
                    _multiverse[row][col].Visualize();
                    _multiverse[row][col].UniverseRunner.AutoKill = true;
                    _cells.Add(_multiverse[row][col]);
                    var img = new Image {Source = _multiverse[row][col].Image};
                    img.SetValue(Canvas.LeftProperty, x);
                    img.SetValue(Canvas.TopProperty, y);
                    CanvasOutput.Children.Add(img);

                    // Universe grid.
                    var rect = new Rectangle
                    {
                        //Fill = _currentGrid[row][col] ? Brushes.Black : Brushes.White,
                        Width = univWidth,
                        Height = univHeight,
                        Stroke = Brushes.Black
                    };
                    rect.SetValue(Canvas.LeftProperty, x);
                    rect.SetValue(Canvas.TopProperty, y);
                    CanvasOutput.Children.Add(rect);

                    // Add label
                    CanvasOutput.Children.Add(lab);
                }
            }

            CanvasOutput.SetValue(WidthProperty, Settings.Default.UniversePaneColumns*univWidth);
            CanvasOutput.SetValue(HeightProperty, Settings.Default.UniversePaneRows*univHeight);
            BtnDeselect.IsEnabled = false;
        }