UIElement.Arrange(Rect) UIElement.Arrange(Rect) UIElement.Arrange(Rect) UIElement.Arrange(Rect) Method

定义

定位子元素,并确定 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 Rect 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默认 WPF 框架级别布局Arrange操作的一部分, 你的实现由在内部调用。Your ArrangeOverride implementation is called internally by Arrange as part of default WPF framework-level layout operations. 如果有子元素, ArrangeOverride则实现还应在每个子元素上调用。ArrangeCoreYour 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默认 WPF 框架级别布局Arrange操作的一部分, 你的实现由在内部调用。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. 如果有子元素, Arrange则实现还应在每个子元素上调用。ArrangeCoreYour 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. 在调用期间, 布局系统使用提供Size的 (availableSize) 参数确定元素的大小要求。 MeasureDuring 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 availableSize通过参数返回所需的最小值。Elements to be laid out return the minimum Size they require through the availableSize parameter.

第一次实例化布局时, 始终会在Measure之前Arrange接收调用。When 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. 调用会自动Arrange失效调用。 MeasureA 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.

布局系统保留两个单独的无效布局队列, 分别用于MeasureArrange一个。The 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.

适用于