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. 相反,应重写类中的 ArrangeCoreInstead, 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 框架级别布局及其布局系统,但如果要从 UIElement 基元素类专门派生 WPF core 级别的元素,这种情况通常并非如此。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.

Windows Presentation Foundation (WPF)Windows Presentation Foundation (WPF) 中,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. 但是,在第一次布局传递后,它可能会收到 Arrange 调用,但没有 Measure;如果更改仅影响 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.

适用于