FrameworkElement.Initialized 事件


初始化此 FrameworkElement 时发生。Occurs when this FrameworkElement is initialized. 此事件与 IsInitialized 属性的值从 false(或未定义)更改为 true 的情况相符。This event coincides with cases where the value of the IsInitialized property changes from false (or undefined) to true.

 event EventHandler ^ Initialized;
public event EventHandler Initialized;
member this.Initialized : EventHandler 
Public Custom Event Initialized As EventHandler 


当调用 EndInitOnVisualParentChanged 方法时,将引发此事件。This event will be raised whenever the EndInit or OnVisualParentChanged methods are called. 对任一方法的调用都可以来自应用程序代码,或在处理 XAMLXAML 页时通过 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML) 处理器行为。Calls to either method could have come from application code, or through the 可扩展应用程序标记语言 (XAML)Extensible Application Markup Language (XAML) processor behavior when a XAMLXAML page is processed.

是否选择处理 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.