FrameworkElement.BeginInit 方法


啟動這個項目的初始化處理序 (Process)。Starts the initialization process for this element.

 virtual void BeginInit();
public virtual void BeginInit ();
abstract member BeginInit : unit -> unit
override this.BeginInit : unit -> unit
Public Overridable Sub BeginInit ()



如果您要以尚未公開或連接專案到任何專案樹狀結構的方式來調整,可以在個別專案上呼叫這個方法。You can call this method on individual elements if you are adjusting them in ways that do not yet expose or connect the element to any element tree. 比方說,您可能已建立新的 FrameworkElement ,但尚未將它附加至任何邏輯樹狀結構。For instance, you might have created a new FrameworkElement, but have not yet attached it to any logical tree. 或者,您的專案在其中的子專案所在的邏輯樹狀結構,可能不會連接到應用程式的視窗或頁面。Or, the logical tree where your element is a child element within it might not be connected to a window or page of the application.


您可以執行這個方法,提供在專案載入程式期間初始化專案之前,應該發生的特殊處理。Implement this method to provide special handling that should happen before your element is initialized during the element loading process.

您的執行應該呼叫基底實作為基底,因為基底 (預設) 實行會設定某些內部旗標來追蹤初始化。Your implementation should call the base implementation, because the base (default) implementation sets some internal flags to keep track of initialization. 其中一個可能的執行方式是使用這個方法來攔截您自己的私用類別初始化常式,這些常式尚未由函式啟用。One possible implementation is to use this method as a hook into your own private class initialization routines that are not already enabled by constructors.

如果在 BeginInit() 呼叫之前呼叫相同元素上的多個時間,基底實作為會擲回例外狀況 EndInit()The base implementation will throw an exception if BeginInit() is called more than one time on the same element prior to EndInit() being called.