i want to know the height of all items my StackPanel
.
What is the difference between:
Height
- Gets or sets the suggested height of the element.ActualHeight
- Gets the rendered height of this element. (readonly)ExtentHeight
- Gets a value that contains the vertical size of the extent. (readonly)ViewportHeight
- Gets a value that contains the vertical size of the content's viewport. (readonly)DesiredSize
- Gets the size that this element computed during the measure pass of the layout process. (readonly)RenderSize
- Gets (or sets, but see Remarks) the final render size of this element.
From MSDN:
Height
Gets or sets the suggested height of the element.Property value:
Double
- The height of the element, in device-independent units (1/96th inch per unit).The height of the element, in device-independent units (1/96th inch per unit).
ActualHeight (readonly)
Gets the rendered height of this element.Property value:
Double
- The element's height, as a value in device-independent units (1/96th inch per unit).This property is a calculated value based on other height inputs, and the layout system. The value is set by the layout system itself, based on an actual rendering pass, and may therefore lag slightly behind the set value of properties such as Height that are the basis of the input change.
Because ActualHeight is a calculated value, you should be aware that there could be multiple or incremental reported changes to it as a result of various operations by the layout system. The layout system may be calculating required measure space for child elements, constraints by the parent element, and so on.
ExtentHeight (readonly)
Gets a value that contains the vertical size of the extent.Property height:
Double
- A Double that represents the vertical size of the extent.The returned value is described in Device Independent Pixels.
ViewportHeight (readonly)
Gets a value that contains the vertical size of the content's viewport.Property value:
Double
- The Double that represents the vertical size of the content's viewport.The returned value is described in Device Independent Pixels.
DesiredSize (readonly)
Gets the size that this element computed during the measure pass of the layout process.Property value:
Size
- The computed size, which becomes the desired size for the arrange pass.The value returned by this property will only be a valid measurement if the value of the IsMeasureValid property is true.
DesiredSize is typically checked as one of the measurement factors when you implement layout behavior overrides such as ArrangeOverride, MeasureOverride, or OnRender (in the OnRender case, you might check RenderSize instead, but this depends on your implementation). Depending on the scenario, DesiredSize might be fully respected by your implementation logic, constraints on DesiredSize might be applied, and such constraints might also change other characteristics of either the parent element or child element. For example, a control that supports scrollable regions (but chooses not to derive from the WPF framework-level controls that already enable scrollable regions) could compare available size to DesiredSize. The control could then set an internal state that enabled scrollbars in the UI for that control. Or, DesiredSize could potentially also be ignored in certain scenarios.
RenderSize Gets the final render size of this element.
Property value:
Size
- The rendered size for this element.This property can be used for checking the applicable render size within layout system overrides such as OnRender or GetLayoutClip.
A more common scenario is handling the SizeChanged event with the class handler override or the OnRenderSizeChanged event.
In my case i want know the desired height of all items in the StackPanel
.
In other words: i want to know height of all items in the StackPanel (before drawing), and if they were to overflow the panel, i will
- delete
- shrink
- scale
- adjust
items to ensure they fit in the StackPanel.
Which means i probably want to get the desired height (ExtentHeight? DesiredSize?) during a resize event (SizeChanged? LayoutUpdated? ) - before any drawing happens (so it's faster).
Most of these properties return zero; so obviously there's some understanding of what these properties mean that i don't know and are not explained in the documentation.