Although both answers given by sLedgem and bathineni are correct, this does not seem to fit my situation. Also why do I want to add them to the layout? If this is convenient for you, you can, but in my case I want them to be in 100% memory, because my helper class, used mainly for printing, had nothing to do with any of the UIElements present on the screen. In this case, obviously, I would not want to pass my LayoutRoot or any other group to my helper class to do this hack!
Request the Silverlight runtime to display items in memory. You need to call the “Dimension” and “Arrange”:
Thus, I usually missed:
stackPanel.Measure(new Size(width, height)); stackPanel.Arrange(new Rect(0, 0, width, height));
before:
_bitmap = new WriteableBitmap(stackPanel, null);
And I can get rid of this line:
stackPanel.UpdateLayout();
Hope this helps someone who comes into this thread and has the same problem as me where I cannot find the LayoutRoot in your helper class.
source share