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. 在預設的 WPF 架構層級版面配置作業中,Arrange 會在內部呼叫您的 ArrangeOverride 執行。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. 相反地,您應該覆寫類別中的 ArrangeCoreInstead, you should override ArrangeCore in your class. 在預設的 WPF 架構層級版面配置作業中,Arrange 會在內部呼叫您的 ArrangeCore 執行。Your ArrangeCore implementation is called internally by Arrange as part of default WPF framework-level layout operations. 不過,這會假設您使用的是 WPF 架構層級配置和其版面配置系統,如果您是從 UIElement 的基底專案類別中特別衍生 WPF 核心層級的專案,這通常不會發生這種情況。However, 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 呼叫期間,配置系統會使用提供的 SizeavailableSize)引數來決定元素的大小需求。During 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. 要配置的元素會透過 availableSize 參數傳回所需的最小 SizeElements to be laid out return the minimum Size they require through the availableSize parameter.

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

版面配置更新通常會以非同步方式進行(一段時間由配置系統決定)。Layout updates generally occur asynchronously (at a time determined by the layout system). 元素可能不會立即反映影響元素調整大小之屬性的變更(例如 Width)。An 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. 如果 Measure 佇列中有元素,則永遠不會排列 Arrange 佇列中的元素。An element in the Arrange queue will never be arranged if there is an element in the Measure queue.

適用於