title: Binding Writeable bitmap to canvas
body: <p>I'm trying to write a simple WPF program to implement Conway's Game of Life.
  My Window consists of a toolbar and a canvas with and embedded Image, on which I'm trying to display a writeable bitmap.</p>
  <p>I have a button on the toolbar which, when clicked,  updates a single generation and then displays the resulting bitmap on the canvas image. I update the image directly with</p>
  <pre><code>img.Source = wbmp;
  </code></pre>
  <p>This works without a problem.</p>
  <p>However, I'd like to show the ongoing updates, without having to click the &quot;Update&quot; button each time. So I tried implementing a loop of 10 iterations. However, the updated image is only shown after the 10th iteration is completed (i.e. I don;t see the first 9 generations)</p>
  <p>My understanding is that I need to bind the Image control to the Writeable bitmap in order to &quot;force&quot; an update each generation. I've tried this with the code below - but now nothing displays at all. Initially I found that the PropertyChanged event didn't seem to be firing but I had no method assigned so, I added PropertyChanged <strong>= delegate {}</strong>;  (I did this because the Internet told me to!)</p>
  <p>I am really not sure where I'm going wrong. I'm rather clueless about WPF and binding in particular. (Much of my code is adapted copy-pasta.) Any help would be greatly appreciated!</p>
  <pre><code>&lt;Canvas Name =&quot;canvas&quot; Grid.Row=&quot;1&quot; Background=&quot;LightGray&quot;&gt;
      &lt;Image Name=&quot;img&quot; Source=&quot;{Binding GoLImage}&quot;/&gt;
  &lt;/Canvas&gt;
  
  public class MyViewModel : INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged = delegate { };
      private ImageSource golImage;  //writeable bitmap;
  
      public ImageSource GoLImage
      {
          get { return golImage; }
          set
          {
              golImage = value;
              PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(GoLImage)));
          }
      }
  
  }
  
   private void Button_Run10_Click(object sender, RoutedEventArgs e)
      {
          BitmapPixelMaker bmp = new BitmapPixelMaker(1200, 800);
          for (int i = 0; i &lt; 10; i++)
          {
              goL.UpdateLifeGrid();  //goL is an instance of my class implementing the Game of Life
              goL.LifeGridTobmp(bmp);
              WriteableBitmap wbmp = bmp.MakeBitmap(96, 96);
  
              //Trying to display bitmap
              MyViewModel golDisplay = new MyViewModel();
              golDisplay.GoLImage = wbmp; //This doesn't automatically display on each iteration
  
          }
      }
  </code></pre>