title: using BitmapSource as Image source in WPF
body: <p>I'm trying to update an Image (_browserScreenshot below) object in XAML by changing the source image every time an event determines the source needs updating.  Right now I have this:</p>
  
  <pre><code>public BitmapSource GetScreen()
  {
      Bitmap bitmap = new Bitmap(app.Browser.ClientRectangle.Width, app.Browser.ClientRectangle.Height);
      app.Browser.DrawToBitmap(bitmap, app.Browser.Bounds);
  
      BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
  
      bitmapSource.Freeze();
  
      bitmap.Dispose();
      bitmap = null;
      return bitmapSource;
  }
  </code></pre>
  
  <p>Then I have an event handler as shown:</p>
  
  <pre><code>app.BitmapSource.Changed += new EventHandler(BitmapSource_Changed);
  
  void BitmapSource_Changed(object sender, EventArgs e)
  {
      Window1._browserScreenshot.Source = app.GetScreen();
  }
  </code></pre>
  
  <p>Now whenever this event fires a new screenshot is taken and the source of the Image (called _browserScreenshot here) control should be updated.  I keep getting an error about changing the IsFrozen propery, but I can't figure out how to change this correctly and have this work the way I want it to.  Thanks in advance everyone.</p>