UIElement.UpdateLayout 方法


確認這個項目的所有視覺化子項目都已正確為配置而更新。Ensures that all visual child elements of this element are properly updated for layout.

 void UpdateLayout();
public void UpdateLayout ();
member this.UpdateLayout : unit -> unit
Public Sub UpdateLayout ()


當您呼叫這個方法時,具有或的專案 IsMeasureValid false IsArrangeValid false 會呼叫專案特定的 MeasureCoreArrangeCore 方法,以強制執行版面配置更新,並驗證所有計算的大小。When you call this method, elements with IsMeasureValidfalse or IsArrangeValidfalse will call element-specific MeasureCore and ArrangeCore methods, which forces layout update, and all computed sizes will be validated.

如果版面配置沒有變更,或者配置的相片順序和度量狀態都無效,則呼叫這個方法不會有任何作用。Calling this method has no effect if layout is unchanged, or if neither arrangement nor measurement state of a layout is invalid. 但是,如果配置在任一方面無效,則 UpdateLayout 呼叫將會取消復原整個版面配置。However, if layout is invalid in either respect, the UpdateLayout call will redo the entire layout. 因此,您應該避免在 UpdateLayout 元素樹狀結構中的每個累加和微小變更之後呼叫。Therefore, you should avoid calling UpdateLayout after each incremental and minor change in the element tree. 版面配置系統會以延後的方式執行元素配置、使用可平衡效能和貨幣的演算法,並使用加權策略來延遲變更至所有子專案,直到所有子項目都有效為止。The layout system will perform element layout in a deferred manner, using an algorithm that balances performance and currency, and with a weighting strategy to defer changes to roots until all child elements are valid. 您應該只在 UpdateLayout 需要更新的大小和位置時才呼叫,而且只有在確定您所控制之屬性的所有變更以及可能會影響版面配置的情況下,才會完成。You should only call UpdateLayout if you absolutely need updated sizes and positions, and only after you are certain that all changes to properties that you control and that may affect layout are completed.