locked
RenderTargetBitmap on a Frame control RRS feed

  • Question

  • I'm trying to export some common reports to pdf (through an open source dll).  Basically I use RenderTargetBitmap to draw UI controls to an ImageSource and then pass this to the Pdf dll and it saves in pdf format.  This works great except for one report.

    This report has a Frame control with a google maps page inside, and it basically shows up as a blank (white) pdf.

    All my elements get a call to Measure and Arrange so they are sized properly, and all other normal controls work.  I also tried saving my RenderTargetBitmap to file with PngBitmapEncoder, and got the same blank image as a result.

    Is there something internal to the Frame control that makes RenderTargetBitmap not work?

    I can post code, but I figured this might be a limitation of the Frame control.
    Monday, March 23, 2009 4:43 PM

Answers

All replies

  • It's a limitation of WPF. When you host a URL, the frame turns into a webbrowser and it is therefore non-WPF content. That's why it will not work with RenderTargetBitmap.
    Controls for WPF, Windows Forms and Silverlight at http://www.divelements.co.uk
    Monday, March 23, 2009 5:25 PM
  • Is there any workaround for this?

    I use a slightly different method for printing that uses a VisualBrush for creating a FixedDocument to pass to a PrintDialog.

    Why does this work and RenderTargetBitmap not?  Do I need to render the VisualBrush on a Canvas (or some random control) first and then RenderTargetBitmap the new control?
    Monday, March 23, 2009 6:59 PM
  • Found this post:

    Uses the printing system to write to an in-memory Xps document and then RenderTargetBitmap the output from that.

    Extremely ugly, but it seems to work.  I added code that crawls the visual tree looking for Frame/WindowsFormsHost elements, so that it can use my earlier method on regular UI elements.  This new method is definitely slower.

    Microsoft should fix this in a future release of .Net or something.
    Monday, March 23, 2009 7:49 PM