Controls to Images behind the scene

[Infragistics] Petar Monov / Monday, February 25, 2013

Hi, 

Here is the sample project upfront as you would prefer. It uses an Infragistics NetAdvantage for WPF 2012 volume 2 control, however the approach should work for all controls.

This is a follow-up on a blog that I had done a while back for creating images from controls: https://es.infragistics.com/community/blogs/b/petar_monov/posts/controls-to-images . The last one used the rendered controls in the visual tree in order to render an image using the RenderTargetBitmap class, of course a few twists. 

This was all cool, however there was always the question of how this can be done without adding the control to the visual tree to be visualized prior to rendering an image. The answer is actually quite simple, you can simulate the control’s lifecycle within the visual tree and get the same result, without actually adding the control anywhere.

 

This is why I decided to write this up in a blog and decided, on what better control to use than the XamBarcode, which many have requested to printed out behind the scene as a result to some data manipulation. All that is needed is an XamBarcode instance (in my case XamQRCodeBarcode) calling its Measure and Arrange measures with some sort of predefined boundaries in which the methods can work (in my case I am setting only the Width, so the XamBarCode can set the height accordingly/proportionally to the data and provide more accurate sizing of the desired image) and as in the above mentioned blog post:

RenderTargetBitmap.Render(xamBarCode);

and recieve this *.png file as result:

Hope you like this.

XamBarcode_to_image_Behind_the_scenes.zip