Window.loaded 在窗口完全加载之前触发 [英] Window.loaded fires before the window is fully loaded

查看:32
本文介绍了Window.loaded 在窗口完全加载之前触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:
Window w =//东西
w.Loaded +=//一些用于截取窗口截图的代码
w.Show();

Loaded 事件在窗口完全加载之前触发,我得到这个图像:

The Loaded event fires before the window is fully loaded and I get this image:

我可以在 w.Show() 之后和屏幕截图之前添加 Thread.Sleep 或其他内容,但我需要为数百个窗口运行这段代码.
我的问题是:当窗口完全加载时,是否会触发另一个事件?或者在不让线程休眠的情况下实现这一目标的某种方法.

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.

谢谢

推荐答案

深入了解 对象生命周期事件 在 MSDN 中可以找到的文章:

Looking into Object Lifetime Events article in MSDN you can find:

Loaded 事件在最终渲染之前引发,但在布局系统已经计算了渲染所需的所有值.加载意味着包含元素的逻辑树内是完整的,并连接到一个演示源提供 HWND 和渲染表面.

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 是数据驱动的 UI 架构,以我们在 WinForms 中习惯的方式使用它并不是很愉快.正如比我更聪明的人曾经说过的那样,WPF 让困难的事情变得微不足道,让琐碎的事情变得困难.

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.

这篇关于Window.loaded 在窗口完全加载之前触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆