title: Displaying a window in C#
body: <p>I am trying to create a WPF UI for an little toy program I have written in C#. The program just finds the shortest path between two points. The display creates a grid of squares that display the type of cell it is (empty space, asteroid, gravity well, gravity influenced, start, finish, and path).</p>
  
  <p>What is the best way for me to run the UI that I have created? I just made the <code>Window</code> variable in my UI a public variable and created an <code>Application</code> in my <code>Program.cs</code> class and called <code>Run</code> on the <code>Window</code>. I have tried <code>Run</code>-ing two different windows at once, and only one would display - how do I get both to display?</p>
  
  <p>Also, is there a way to make it so that my grid updates whenever the contents of the array that describe each cell change? e.g. if a cell changed from an asteroid to empty space, which has a different color, is there a way to make my UI know that it changed and update accordingly?</p>
  
  <p>Here is the source code for the UI:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Media;
  using System.Windows.Shapes;
  
  namespace SpaceProbe
  {
      public class SpaceProbeView
      {
          public Window window = new Window();
          public Window optionWindow = new Window();
          Canvas canvas = new Canvas();
          private int cellSize = 25;
          SpaceProbeModel model;
          int rowAndColumnSize;
          SolidColorBrush emptySpaceBrush = Brushes.DarkBlue;
          SolidColorBrush asteroidBrush = Brushes.DarkGreen;
          SolidColorBrush gravityWellBrush = Brushes.Magenta;
          SolidColorBrush gravityInfluencedBrush = Brushes.DarkMagenta;
          SolidColorBrush pathBrush = Brushes.DarkTurquoise;
          SolidColorBrush startBrush = Brushes.Black;
          SolidColorBrush finishBrush = Brushes.DarkOrange;
          Brush outlineBrush = Brushes.Black;
  
          public SpaceProbeView(int size)
          {
              rowAndColumnSize = size;
              window.Title = "Space Probe";
              canvas.Width = rowAndColumnSize * cellSize;
              canvas.Height = rowAndColumnSize * cellSize;
              window.Width = rowAndColumnSize * cellSize;
              window.Height = rowAndColumnSize * cellSize;
              window.Content = canvas;
              window.SizeToContent = SizeToContent.WidthAndHeight;
  
              //window.Show();
              optionWindow.Width = 100;
              optionWindow.Height = 200;
              //optionWindow.Show();
          }
  
          public void SetModel(SpaceProbeModel aModel)
          {
              model = aModel;
              for (int row = 0; row &lt; rowAndColumnSize; row++)
              {
                  for (int column = 0; column &lt; rowAndColumnSize; column++)
                  {
                      Rectangle rect = new Rectangle();
                      rect.Width = cellSize;
                      rect.Height = cellSize;
                      rect.Stroke = outlineBrush;
  
                      switch (model.cellType[row, column])
                      {
                          case SpaceProbeModel.type.start:
                              rect.Fill = startBrush;
                              break;
                          case SpaceProbeModel.type.finish:
                              rect.Fill = finishBrush;
                              break;
                          case SpaceProbeModel.type.asteroid:
                              rect.Fill = asteroidBrush;
                              break;
                          case SpaceProbeModel.type.gravityInfluenced:
                              rect.Fill = gravityInfluencedBrush;
                              break;
                          case SpaceProbeModel.type.gravityWell:
                              rect.Fill = gravityWellBrush;
                              break;
                          case SpaceProbeModel.type.empty:
                              rect.Fill = emptySpaceBrush;
                              break;
                          case SpaceProbeModel.type.path:
                              rect.Fill = pathBrush;
                              break;
                      }
                      Canvas.SetTop(rect, row * cellSize);
                      Canvas.SetLeft(rect, column * cellSize);
                      canvas.Children.Add(rect);
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>and my <code>Program.cs</code> class:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows;
  
  namespace SpaceProbe
  {
      class Program
      {
          [STAThread]
          static void Main(string[] args)
          {
              SpaceProbeView view = new SpaceProbeView(30);
              SpaceProbeModel model = new SpaceProbeModel(30, 20, 1);
              model.Start = new SpaceProbeModel.CellPair(5, 5);
              model.FindShortestPath(20, 25);
              view.SetModel(model);
              Application app = new Application();
              app.Run(view.window);
          }
      }
  }
  </code></pre>