I have this code:Window w = // something
w.Loaded += // some code to take a screenshot of the window
w.Show();
The Loaded event fires before the window is fully loaded and I get this image:
I could add a Thread.Sleep
or something after w.Show()
and before the screenshot but I need to run this piece of code for hundreds of windows.
My question is: Is there another event that fires when the window is fully loaded? or some way to achieve this without putting the thread to sleep.
Thanks
Looking into Object Lifetime Events article in MSDN you can find:
The Loaded event is raised before the final rendering, but after the layout system has calculated all necessary values for rendering. Loaded entails that the logical tree that an element is contained within is complete, and connects to a presentation source that provides the HWND and the rendering surface.
You should try some alternative events which are not exactly suited for your need. You should try in following order:
Take note that these events may fire multiple times during lifetime of your window, so write your application with that in mind.
WPF is data driven UI architecture and it's not very pleasant to work with in a way we are used to in WinForms. As someone smarter than me once said, WPF makes hard things trivial and trivial things hard.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With