Appropriate way to force loading of a WPF Visual Appropriate way to force loading of a WPF Visual wpf wpf

Appropriate way to force loading of a WPF Visual


The items you want to print need to be added to the visual tree in WPF in order for the Measure and Arrange processes to be called on all the elements in the visual tree you want to show / print or otherwise display.

I haven't done this for a while but you may find that adding these items to a ViewPort in the background and then printing them solves the issue. This should get around the need for actually displaying them on the screen and thus the user seeing them whilst also forcing the Measure / Arrange processes.


I had the same problem. In my case I only call: Visual.UpdateLayout() before trying to work with it. As said by Jammer, it will automatically force Measure / Arrange processes.

I did it on window. If you have any problem, you probably should set the Visual Height and Width before call UpdateLayout().

Eric


I had the same issue. Solved by ApplyTemplate().

It force to builds visual tree of an Framework element.