Skip to content

Latest commit

 

History

History
34 lines (22 loc) · 2.82 KB

uielement_desiredsize.md

File metadata and controls

34 lines (22 loc) · 2.82 KB
-api-id -api-type
P:Microsoft.UI.Xaml.UIElement.DesiredSize
winrt property

Microsoft.UI.Xaml.UIElement.DesiredSize

-description

Gets the size that this UIElement computed during the measure pass of the layout process.

-property-value

The size that this UIElement computed during the measure pass of the layout process.

-remarks

DesiredSize is typically checked as one of the measurement factors when you implement layout behavior overrides such as ArrangeOverride or MeasureOverride. Depending on the parent container's layout logic, DesiredSize might be fully respected, 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 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 be ignored and the element always gets a layout that is sized by other considerations such as checking attached property values.

DesiredSize won't contain a useful value unless at least one "Measure" pass of layout has run on the element.

DesiredSize is really only intended for use when you define your own layout override methods. If you're just interested in the size of an element in your app's UI at run time, then you should use the ActualWidth and ActualHeight properties instead. You might be checking size this way if an element is influenced by dynamic layout techniques such as star sizing of Grid cells. Rely on ActualWidth and ActualHeight values only in situations that are sure to be after layout has run: for example, in Loaded events, or triggered by user actions that are only possible after the UI has been rendered initially.

-examples

This example queries DesiredSize as part of the child iteration for an ArrangeOverride implementation.

[!code-csharp2]

-see-also

ArrangeOverride, MeasureOverride, Arrange, Measure , Measure