FrameworkElement.Loaded 事件

定义

当对元素进行布局、呈现,且可将其用于交互时发生。Occurs when the element is laid out, rendered, and ready for interaction.

public:
 event System::Windows::RoutedEventHandler ^ Loaded;
public event System.Windows.RoutedEventHandler Loaded;
member this.Loaded : System.Windows.RoutedEventHandler 
Public Custom Event Loaded As RoutedEventHandler 

注解

Loaded 通常是在元素初始化序列中引发的最后一个事件。Loaded is usually the last event raised in an element initialization sequence. 它将始终在 Initialized后引发。It will always be raised after Initialized. 是否选择处理 LoadedInitialized 取决于你的要求。Whether you choose to handle Loaded or Initialized depends on your requirements. 如果不需要读取元素属性,而想要重置属性,并且不需要任何布局信息,Initialized 可能是要采取的更好事件。If you do not need to read element properties, intend to reset properties, and do not need any layout information, Initialized might be the better event to act upon. 如果需要元素的所有属性均可供使用,并且要设置可能重置布局的属性,Loaded 可能是要执行操作的更好事件。If you need all properties of the element to be available, and you will be setting properties that are likely to reset the layout, Loaded might be the better event to act upon. 如果处理程序重置由布局系统解释的任何属性,以表示需要新的布局传递,请注意重入。Be careful of reentrancy if your handler resets any properties that are interpreted by the layout system to mean that a new layout pass is required. (如果您不确定哪些属性在更改时需要新的布局传递,则您可能需要检查属性的 FrameworkPropertyMetadata 值。)(You might need to check the FrameworkPropertyMetadata values on the property if you are unsure of which properties can require a new layout pass if they are changed.)

有关 FrameworkElement的对象事件顺序以及多个相关应用程序和元素类的详细信息,请参阅对象生存期事件For more information about the sequence of object events for a FrameworkElement, and also for several related application and element classes, see Object Lifetime Events.

直接路由事件不遵循路由,它们只能在引发它们的同一元素内进行处理。Direct routed events do not follow a route, they are only handled within the same element on which they are raised. 直接路由事件支持其他路由事件行为:它们支持可访问的处理程序集合,并且可用作样式中的 EventTriggerDirect routed events do support other routed event behavior: they support an accessible handlers collection, and can be used as an EventTrigger in a style.

由于用户启动的系统主题更改,LoadedUnloaded 可能会在控件上引发。Loaded and Unloaded might both be raised on controls as a result of user-initiated system theme changes. 主题更改会导致控件模板和包含的可视化树失效,这进而导致整个控件被卸载和重新加载。A theme change causes an invalidation of the control template and the contained visual tree, which in turn causes the entire control to unload and reload. 因此 Loaded 无法假定仅在第一次通过导航到页面时才会发生。Therefore Loaded cannot be assumed to occur only when a page is first loaded through navigation to the page.

路由事件信息Routed Event Information

标识符字段Identifier field LoadedEvent
路由策略Routing strategy 直接Direct
委托Delegate RoutedEventHandler

适用于

另请参阅