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. 在调用期间, 元素通过availableSize使用输入来确定其大小要求。 MeasureDuring 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可以是从零到无限大的任何数字。availableSize can be any number from zero to infinite. 参与布局的元素应返回给定Size availableSize的所需的最小值。Elements participating in layout should return the minimum Size they require for a given availableSize.

第一次实例化布局时, 始终会在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 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.

布局系统保留两个单独的无效布局队列, 分别用于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 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. 如果Measure队列中有Arrange元素, 则永远不会排列队列中的元素。An element in the Arrange queue will never be arranged if there is an element in the Measure queue.

适用于