Search code examples
c#wpfdrawingrendering

How to know when a control (or window) has been rendered (drawn) in WPF?


I need to store the content of a Window into an image, save it and close the window. If I close the window on the Loaded event the image contains the Window with some items are drawn ok, some others are only half drawn or distorted while others are not on the image.

If I put a timer and close the window after a certain amount of time (something between 250ms and 1sec depending on the complexity of the window) the images are all ok.

Looks like the window needs some time to completely render itself. Is there a way to know when this rendering has been done to avoid using a Timer and closing the window when we know it has completed its rendering?

Thanks.


Solution

  • I think you are looking for the ContentRendered event