Skip to content

Latest commit

 

History

History
48 lines (29 loc) · 3.91 KB

frameworkelement_arrangeoverride_1795048387.md

File metadata and controls

48 lines (29 loc) · 3.91 KB
-api-id -api-type
M:Windows.UI.Xaml.FrameworkElement.ArrangeOverride(Windows.Foundation.Size)
winrt method

Windows.UI.Xaml.FrameworkElement.ArrangeOverride

-description

Provides the behavior for the "Arrange" pass of layout. Classes can override this method to define their own "Arrange" pass behavior.

-parameters

-param finalSize

The final area within the parent that this object should use to arrange itself and its children.

-returns

The actual size that is used after the element is arranged in layout.

-remarks

This method has a default implementation that performs built-in layout for most FrameworkElement derived classes. ArrangeOverride provides the behavior for Arrange, whenever Arrange is called either by internal layout logic or your own app's code, including any ArrangeOverride methods of your own for other classes. If you are producing a templated control, the ArrangeOverride logic defines your control's specific "Arrange" pass layout logic.

The general design of how elements go through a layout process when your app runs is divided into two steps: a "Measure" pass, and then an "Arrange" pass. Control authors (or panel authors) who want to customize the "Arrange" pass of layout processing should override ArrangeOverride. The implementation pattern should call Arrange on each visible child object, and pass the final desired size for each child object as the finalRect parameter. If Arrange isn't called, the child object is not rendered.

Several existing non-sealed classes provide override implementations of this method. Prominent ones include StackPanel and Grid. Typically, the behavior of ArrangeOverride produces a finalSize that does not violate any user-defined values that are placed on the layout container itself. For example, the finalSize is not typically larger than the container's Height and Width, accounting for Margin or Padding values that affect the content area. Controls that specifically have a scenario for exceeding the container size could return a larger value, but anyone using that control must account for the clipping and positioning issues that result from it. The value that an ArrangeOverride implementation passes to Arrange for each child object is generally the value that is set in DesiredSize by the previous Measure call.

-examples

This example implements ArrangeOverride to customize the "Arrange" pass logic for a custom panel implementation. Note in particular these aspects of the code:

  • Iterates over children.
  • For each child, calls Arrange, using a Rect where Height and Width are based on DesiredSize, and X and Y are based on logic that is specific to the panel.
  • Returns its size (in this case, this simple panel returns a fixed size rather than a size calculated on accumulating the arranged Rect value measurements).

[!code-csharp2]

[!code-vb2]

-see-also

Arrange, MeasureOverride, Define layouts with XAML 4162-1c9c-48f4-8a94-34976fb17079)