FrameworkElement.ApplyTemplate FrameworkElement.ApplyTemplate FrameworkElement.ApplyTemplate FrameworkElement.ApplyTemplate Method

定義

如有必要,則建置目前範本的視覺化樹狀結構,並傳回值,指出此呼叫是否已重建視覺化樹狀結構。Builds the current template's visual tree if necessary, and returns a value that indicates whether the visual tree was rebuilt by this call.

public:
 bool ApplyTemplate();
public bool ApplyTemplate ();
member this.ApplyTemplate : unit -> bool
Public Function ApplyTemplate () As Boolean

傳回

如果視覺項目已加入樹狀結構,則為 true;否則傳回 falsetrue if visuals were added to the tree; returns false otherwise.

備註

應用程式可以呼叫這個方法, 以確保元素的視覺化樹狀結構已完成。Applications can call this method to guarantee that the visual tree of an element is complete. 如果程式碼將檢查樹狀結構中的子專案, 則此保證步驟可能是必要的。This guarantee step might be necessary if code will be checking the child elements in the tree. 對於應用程式中的一般專案邏輯ApplyTemplate而言, 不需要呼叫, 因為範本會自動套用至其存留期內適當時間點的元素。For typical element logic within applications, calling ApplyTemplate is not necessary, because templates will be applied to elements at an appropriate point in their lifetimes automatically.

ApplyTemplateWPF 架構層級版面配置系統會針對每個量值傳遞呼叫。ApplyTemplate is called on every Measure pass by the WPF framework-level layout system.

FrameworkElement衍生類別可以使用OnApplyTemplate類別處理常式, 以在明確呼叫這個方法的情況下, 或由配置系統來通知。FrameworkElement derived classes can use the OnApplyTemplate class handler to be notified of cases where this method was called explicitly, or by the layout system. OnApplyTemplate在完整產生範本並將其附加至邏輯樹狀結構之後, 會呼叫。OnApplyTemplate is called after the template is completely generated and attached to the logical tree.

適用於

另請參閱