UIElement.Arrange(Rect) 方法

定義

放置子項目,並且判斷 UIElement 的大小。Positions child elements and determines a size for a UIElement. 父項目從 ArrangeCore(Rect) 實作 (或 WPF 架構層級對等項目) 中呼叫此方法,以形成遞迴配置更新。Parent elements call this method from their ArrangeCore(Rect) implementation (or a WPF framework-level equivalent) to form a recursive layout update. 這個方法會構成配置更新的第二個階段。This method constitutes the second pass of a layout update.

public:
 void Arrange(System::Windows::Rect finalRect);
public void Arrange (System.Windows.Rect finalRect);
member this.Arrange : System.Windows.Rect -> unit
Public Sub Arrange (finalRect As Rect)

參數

finalRect
Rect

父代為子項目計算的最終大小,提供作為 Rect 執行個體。The final size that the parent computes for the child element, provided as a Rect instance.

備註

針對 WPF 架構層級的專案衍生案例, Arrange 除非您遮蔽) ,否則不應該 (的行為。For WPF framework-level element deriving scenarios, behavior for Arrange should not (and cannot, unless you shadow) be changed. 相反地,您應該覆寫 ArrangeOverride 類別中的實作為。Instead, you should override the ArrangeOverride implementation in your class. ArrangeOverride系統會在內部呼叫您的實 Arrange 作為預設 WPF 架構層級版面配置作業的一部分。Your ArrangeOverride implementation is called internally by Arrange as part of default WPF framework-level layout operations. ArrangeCore ArrangeOverride 如果它有子項目,則您的實也應該在每個子項目上呼叫。Your ArrangeCore implementation should also call ArrangeOverride on each child element, if it has child elements.

針對 WPF 核心層級專案衍生案例, Arrange 除非您將) 變更,否則的行為不應 (且無法進行。For WPF core-level element deriving scenarios, the behavior for Arrange should not (and cannot, unless you shadow) be changed. 相反地,您應該 ArrangeCore 在類別中覆寫。Instead, you should override ArrangeCore in your class. ArrangeCore系統會在內部呼叫您的實 Arrange 作為預設 WPF 架構層級版面配置作業的一部分。Your ArrangeCore implementation is called internally by Arrange as part of default WPF framework-level layout operations. 不過,這會假設您使用 WPF 架構層級的版面配置和它的版面配置系統,如果您是從基底專案類別的 WPF 核心層級明確地衍生元素,這通常不會發生 UIElementHowever, this assumes you are using WPF framework-level layout and its layout system, which is often not the case if you are specifically deriving elements at the WPF core-level from the UIElement base element class. ArrangeCore Arrange 如果它有子項目,則您的實也應該在每個子項目上呼叫。Your ArrangeCore implementation should also call Arrange on each child element, if it has child elements. 請注意,WPF 核心層級案例表示您未使用 FrameworkElement 衍生類別,因為 FrameworkElement 密封 ArrangeCoreNote that the WPF core-level scenario implies that you are not using a FrameworkElement derived class, because FrameworkElement seals ArrangeCore.

在中計算 WPF 架構層級的版面配置位置 Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 是由 Measure 呼叫和 Arrange 呼叫所組成。Computation of WPF framework-level layout positioning in Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) consists of a Measure call and an Arrange call. Measure 呼叫期間,配置系統會使用提供的 Size () 引數來判斷元素的大小需求 availableSizeDuring the Measure call, the layout system determines an element's size requirements using a provided Size (availableSize) argument. 在呼叫期間,版面配置系統會完成專案的周 Arrange 框方塊大小和位置。During the Arrange call, the layout system finalizes the size and position of an element's bounding box. 如需詳細資訊,請參閱配置For more information, see Layout.

availableSize 可以是從零到無限大的任何數位。availableSize can be any number from zero to infinity. 要配置的元素會透過參數傳回它們所需的最小值 Size availableSizeElements to be laid out return the minimum Size they require through the availableSize parameter.

當版面配置第一次具現化時,一律會 Measure 先接收呼叫 ArrangeWhen a layout is first instantiated, it always receives a Measure call before Arrange. 不過,在第一次配置通過之後,它可能會收到 Arrange 沒有的呼叫 Measure ; 當只影響的屬性變更時,就會發生這種情況, Arrange 例如對齊) 的 (,或當父系收到 Arrange 沒有的時 MeasureHowever, 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. Measure呼叫會自動使呼叫失效 ArrangeA Measure call will automatically invalidate an Arrange call.

版面配置更新通常會在配置系統) 所決定的時間以非同步方式進行 (。Layout updates generally occur asynchronously (at a time determined by the layout system). 元素可能不會立即反映影響專案調整大小 ((例如) )之屬性的變更 WidthAn element might not immediately reflect changes to properties that affect element sizing (such as Width).

注意

您可以使用方法強制執行版面配置更新 UpdateLayout ; 不過,不建議呼叫此函式,因為它通常是不必要的,而且可能會導致效能不佳。Layout updates can be forced by using the UpdateLayout method; however, calling this function is not recommended, as it is usually unnecessary and can cause poor performance. 在許多情況下 UpdateLayout ,可能會有適當的呼叫,因此版面配置系統可能已經在處理更新。In many situations where calling UpdateLayout might be appropriate, the layout system will probably already be processing updates. 版面配置系統可以處理配置變更,以將所有必要的更新做為封裝的一部分進行優化。The layout system can process layout changes in a manner that can optimize all necessary updates as part of a package.

版面配置系統會將兩個不同的配置佇列保留為不正確版面配置,一個用於 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. 樹狀結構中較高層級的元素位於佇列頂端,以避免因為父系的重複變更所造成的重複版面配置。Elements higher in the tree are at the top of the queue, in order 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 valid.

更新版面配置時, Measure 會先清空佇列,然後排在 Arrange 佇列中。When updating layout, the Measure queue is emptied first, followed by the Arrange queue. Arrange如果佇列中有元素,則不會排列佇列中的元素 MeasureAn element in the Arrange queue will never be arranged if there is an element in the Measure queue.

適用於