RunWhenNearViewport(Control, Action) Method

Definition

Assembly MarkView.Avalonia.dll

Calls realize once, the first time element is laid out within one viewport height of the visible part of its scroll viewer (or of its window, outside one). It is called during the layout pass that brings the element near, before that pass is rendered, so content it builds is laid out before it is ever seen. Call it before the element is attached to a visual tree, as a renderer does.

public static void RunWhenNearViewport(Control element, Action realize)

Parameters

element
Avalonia.Controls.Control

The element whose position decides; it hosts the deferred content.

realize
Action

Builds the deferred content.

Remarks

Avalonia's Avalonia.Layout.Layoutable.EffectiveViewportChanged clips the viewport to every ancestor that clips its content: an image inside a paragraph (a Avalonia.Controls.TextBlock clips to its bounds) would see nothing of the viewport until the paragraph itself scrolled into view. So the event is listened to on the outermost such ancestor below the scroll viewer, and the element's own bounds are measured against it. The layout manager only tracks that ancestor while the element is attached: an element that is never shown, or is discarded first, never calls realize and is collected normally.