Silverlight 3 Quick Tip #1: How to use WritableBitmap
eWith this post I’m starting the series of Quick Tips post, this time for Silverlight 3.
Today I’ll show how to use WritableBitmap class to paint with content of any Visual element. Let’s start – I created very simple UI with UserControl inside a stack panels and bunch of buttons to control my sample logic
By pressing “Paint control” button I’d like to fill the image in the cell with “Control Image” caption with the picture of the control from the content control in the cell with “Control Instance”. The code is actually very simple:
WriteableBitmap bitmap = new WriteableBitmap(350, 150, PixelFormats.Pbgra32);
bitmap.Render(contentPlaceholder.Content as UIElement, (contentPlaceholder.Content as UIElement).RenderTransform);
BitmapSource source = bitmap;
imgControlDrawing.Source = source;
Sources as usual – attached here.
Stay tuned to more tips and enjoy,
Alex