UIElement.InvalidateMeasure 方法


使元素度量状态(布局)无效。Invalidates the measurement state (layout) for the element.

 void InvalidateMeasure();
public void InvalidateMeasure ();
member this.InvalidateMeasure : unit -> unit
Public Sub InvalidateMeasure ()


调用此方法还会在内部调用 InvalidateArrange,无需连续调用 InvalidateMeasureInvalidateArrangeCalling this method also calls InvalidateArrange internally, there is no need to call InvalidateMeasure and InvalidateArrange in succession. 失效后,该元素将更新其布局,这将以异步方式发生,除非调用 UpdateLayout 来强制进行同步布局更改。After the invalidation, the element will have its layout updated, which will occur asynchronously, unless UpdateLayout is called to force a synchronous layout change.

WPF 框架级别布局系统自行处理元素的可视化树中的更改,并且在大多数常见的布局失效情况下,布局系统在必要时将调用与此方法等效的。The WPF framework-level layout system does its own handling of changes in the visual tree of an element, and in most common layout invalidation cases the layout system is calling the equivalent of this method when necessary. 仅当生成可直接操作元素树或类似高级方案的完整布局实现时,才应调用此方法。You should only call this method if you are producing a complete layout implementation, which does direct manipulation of the element tree, or similar advanced scenarios. 一种高级方案是,如果您要为不在 FreezableFrameworkElement 派生类上的依赖属性创建 PropertyChangedCallback,而该属性在更改时仍会影响布局的测量处理过程。One such advanced scenario is if you are creating a PropertyChangedCallback for a dependency property that is not on a Freezable or FrameworkElement derived class that still influences the measure pass of layout when it changes.

频繁调用 InvalidateMeasure 或特别是 UpdateLayout 会对性能产生重大影响。Frequent calls to InvalidateMeasure or in particular to UpdateLayout have significant performance consequences. 因此,请避免调用此方法,除非你在对代码中的其他 Api 进行后续调用时绝对需要精确布局状态。Therefore, avoid calling this method unless you absolutely require precise layout state for subsequent calls to other APIs in your code.