title: Force rendering of a WPF control in memory
body: <p>I have the following code:</p>
  
  <pre><code>void Test()
  {
      currentImage.Source = GetBitmap();
      RenderTargetBitmap rtb = new RenderTargetBitmap(100, 100, 96.0, 96.0, PixelFormats.Default);
      rtb.Render(currentImage);
  }
  </code></pre>
  
  <p>This code is supposed to render currentImage, which is an Image control in my xaml to a RenderTargetBitmap.</p>
  
  <p>It doesn't work, rtb returns a blank image, the problem is currentImage didn't render itself yet and so this behavior is expected, I think...</p>
  
  <p>To workaround this problem, I wrote this code:</p>
  
  <pre><code>void Test()
  {
      currentImage.Source = GetBitmap();
  
      this.Dispatcher.BeginInvoke((Action)delegate()
      {
          RenderTargetBitmap rtb = new RenderTargetBitmap(100, 100, 96.0, 96.0, PixelFormats.Default);
          rtb.Render(currentImage);
      }, System.Windows.Threading.DispatcherPriority.Render, null);
  
  }
  </code></pre>
  
  <p>Basically, I wait for currentImage to be rendered and then I can get it properly rendered to my RenderTargetBitmap.</p>
  
  <p>Is there any way to make it work without using this workaround? Force the Image control to render in memory maybe?</p>
  
  <p>thanks!</p>