UIElement.OnChildDesiredSizeChanged(UIElement) 方法


會在調整子項目的大小時支援配置行為。Supports layout behavior when a child element is resized.

 virtual void OnChildDesiredSizeChanged(System::Windows::UIElement ^ child);
protected virtual void OnChildDesiredSizeChanged (System.Windows.UIElement child);
abstract member OnChildDesiredSizeChanged : System.Windows.UIElement -> unit
override this.OnChildDesiredSizeChanged : System.Windows.UIElement -> unit
Protected Overridable Sub OnChildDesiredSizeChanged (child As UIElement)



正在調整大小的子項目。The child element that is being resized.


您的應用程式程式碼通常不會呼叫這個方法。This method is typically not called by your application code. 它會公開,讓衍生的專案類別可以進一步檢查其本身可能不正確版面配置狀態。It is exposed so that derived element classes can make further checks on their own possibly invalid layout state. 類別也可以嘗試優化,以根據子專案的大小變更,將配置傳遞的處理時間降至最低。Classes could also attempt optimizations to minimize the processing time for a layout pass based on size changes to child elements. 實作為控制項的範例衍生元素類別 OnChildDesiredSizeChanged GridAn example derived element class that implements OnChildDesiredSizeChanged is the Grid control.


OnChildDesiredSizeChanged(UIElement)方法本身會有呼叫的預設實值 InvalidateMeasure()The OnChildDesiredSizeChanged(UIElement) method has the default implementation of calling InvalidateMeasure() on itself. 一般的實作為:執行您自己的專案所支援的任何優化,然後通常會 OnChildDesiredSizeChanged(UIElement) 從至少一個程式碼分支呼叫基底, (其中一個會針對您自己的量值快取邏輯) 指出「已變更」狀態。A typical implementation would be: do whatever optimization your own element supports, and then typically call base OnChildDesiredSizeChanged(UIElement) from at least one of the code branches (the one that indicated "dirty" state per your own measure caching logic).

只有在版面配置處理中的子系本身產生大小變更時,才會呼叫這個方法。This method is only called in the layout processing if it was the child itself that originated the size changes. 否則,如果父元素 Measure(Size) 根據配置系統規則起始傳遞,則父元素會重新計算版面配置。Otherwise, if the parent element initiates the Measure(Size) pass, according to the layout system rules, the parent is recalculating layout already. 版面配置系統會以子系對父系的連續處理配置,因此不需要從子項目版面配置呼叫傳回父元素的大小。The layout system processes layout in the order of child-to-parent, so no return to parent element sizing from the child element layout calls is necessary.