UIElement.Measure(Size) UIElement.Measure(Size) UIElement.Measure(Size) UIElement.Measure(Size) Method

定義

更新 UIElementDesiredSizeUpdates the DesiredSize of a UIElement. 父項目從本身的 MeasureCore(Size) 實作中呼叫此方法,以形成遞迴配置更新。Parent elements call this method from their own MeasureCore(Size) implementations to form a recursive layout update. 呼叫此方法即構成配置更新的第一次傳遞 (「量值」傳遞)。Calling this method constitutes the first pass (the "Measure" pass) of a layout update.

public:
 void Measure(System::Windows::Size availableSize);
public void Measure (System.Windows.Size availableSize);
member this.Measure : System.Windows.Size -> unit
Public Sub Measure (availableSize As Size)

參數

availableSize
Size Size Size Size

可供父項目用來配置子項目的空間。The available space that a parent element can allocate a child element. 子項目可以要求比可用空間更大的空間;如果在目前項目的內容模型中能夠捲動,就可能容納提供的大小。A child element can request a larger space than what is available; the provided size might be accommodated if scrolling is possible in the content model for the current element.

備註

計算版面配置定位Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF)組成Measure呼叫和Arrange呼叫。Computation of layout positioning in Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) is comprised of a Measure call and an Arrange call. 期間Measure呼叫時,項目決定其大小需求使用availableSize輸入。During the Measure call, an element determines its size requirements by using an availableSize input. 期間Arrange完成呼叫時,項目大小。During the Arrange call, the element size is finalized.

availableSize 可為任何介於 0 到無限。availableSize can be any number from zero to infinite. 參與配置的項目應該會傳回最小Size他們需要指定availableSizeElements participating in layout should return the minimum Size they require for a given availableSize.

當第一次執行個體化的版面配置時,它一律會收到Measure之前,先呼叫ArrangeWhen a layout is first instantiated, it always receives a Measure call before Arrange. 不過之後第一次的版面配置傳遞,, 它可能會收到Arrange呼叫,而不Measure; 這種情形只會影響的屬性時Arrange變更 (例如對齊),或是當父系收到Arrange沒有Measure.However, after the first layout pass, it may receive an Arrange call without a Measure; this can happen when a property that affects only Arrange is changed (such as alignment), or when the parent receives an Arrange without a Measure. AMeasure呼叫會自動失效Arrange呼叫。A Measure call will automatically invalidate an Arrange call.

如此主執行緒沒有在等待每個可能的配置變更,會以非同步方式發生配置更新。Layout updates happen asynchronously, such that the main thread is not waiting for every possible layout change. 查詢透過程式碼後置檢查屬性值的項目可能不會立即反映變更互動的調整大小或版面配置特性的屬性 (Width內容,例如)。Querying an element via code-behind checking of property values may not immediately reflect changes to properties that interact with the sizing or layout characteristics (the Width property, for example).

注意

版面配置更新可以強制使用UpdateLayout方法。Layout updates can be forced by using the UpdateLayout method. 不過,呼叫這個方法通常不需要而且可能會導致效能不佳。However, calling this method is usually unnecessary and can cause poor performance.

版面配置系統會保留兩個不同的佇列,不正確的版面配置,一個用於Measure,另一個用於ArrangeThe layout system keeps two separate queues of invalid layouts, one for Measure and one for Arrange. 配置的佇列會根據執行配置; 元素的視覺化樹狀結構中的項目順序排序在樹狀結構中較高的項目是佇列的頂端,以避免重複的變更,在父代所造成的備援配置。The layout queue is sorted based upon the order of elements in the visual tree of the element performing layout; elements higher in the tree are at the top of the queue, to avoid redundant layouts caused by repeated changes in parents. 自動從佇列中移除重複的項目,如果他們已驗證配置的項目會自動會從佇列移除。Duplicate entries are automatically removed from the queue, and elements are automatically removed from the queue if they are already layout-validated.

更新配置時Measure佇列清空第一,後面接著Arrange佇列。When updating layout, the Measure queue is emptied first, followed by the Arrange queue. 中的項目Arrange中的項目時,就永遠不會排列佇列Measure佇列。An element in the Arrange queue will never be arranged if there is an element in the Measure queue.

適用於