Table of Contents

Class Magnet

Namespace
Nalu
Assembly
Nalu.Maui.Layouts.dll

A constraint-based Layout: every child is positioned by anchoring its sides to other children, virtual nodes (barriers, guidelines, chains) or the parent stage.

public class Magnet : Layout, INotifyPropertyChanged, IEffectControlProvider, IToolTipElement, IContextFlyoutElement, IAnimatable, IViewController, IVisualElementController, IElementController, IGestureController, IGestureRecognizers, IPropertyMapperView, IHotReloadableView, IReplaceableView, ILayout, IView, IElement, ITransform, IContainer, IList<IView>, ICollection<IView>, IEnumerable<IView>, IEnumerable, ISafeAreaView, IPadding, ICrossPlatformLayout, IBindableLayout, IVisualTreeElement
Inheritance
Magnet
Implements
Inherited Members
Extension Methods

Fields

AboveProperty

Attached shortcut (set-only): BottomTo = target.Top.

public static readonly BindableProperty AboveProperty

Field Value

BindableProperty

AfterProperty

Attached shortcut (set-only): LeftTo = target.Right — "avatar,12", "avatar,12,gone:0".

public static readonly BindableProperty AfterProperty

Field Value

BindableProperty

AlignBottomProperty

Attached shortcut (set-only): BottomTo = target.Bottom.

public static readonly BindableProperty AlignBottomProperty

Field Value

BindableProperty

AlignLeftProperty

Attached shortcut (set-only): LeftTo = target.Left.

public static readonly BindableProperty AlignLeftProperty

Field Value

BindableProperty

AlignRightProperty

Attached shortcut (set-only): RightTo = target.Right.

public static readonly BindableProperty AlignRightProperty

Field Value

BindableProperty

AlignTopProperty

Attached shortcut (set-only): TopTo = target.Top.

public static readonly BindableProperty AlignTopProperty

Field Value

BindableProperty

BeforeProperty

Attached shortcut (set-only): RightTo = target.Left.

public static readonly BindableProperty BeforeProperty

Field Value

BindableProperty

BelowProperty

Attached shortcut (set-only): TopTo = target.Bottom.

public static readonly BindableProperty BelowProperty

Field Value

BindableProperty

BottomToProperty

Attached (set-only): BottomTo of a child.

public static readonly BindableProperty BottomToProperty

Field Value

BindableProperty

ConstraintsProperty

Attached property holding the inline MagnetView of a child (created lazily by GetConstraints(BindableObject)).

public static readonly BindableProperty ConstraintsProperty

Field Value

BindableProperty

DefinitionProperty

Bindable property for Definition.

public static readonly BindableProperty DefinitionProperty

Field Value

BindableProperty

FillHeightProperty

Attached shortcut (set-only): top and bottom anchored to the target and HeightSizing="*".

public static readonly BindableProperty FillHeightProperty

Field Value

BindableProperty

FillWidthProperty

Attached shortcut (set-only): left and right anchored to the target and WidthSizing="*".

public static readonly BindableProperty FillWidthProperty

Field Value

BindableProperty

HeightSizingProperty

Attached (set-only): HeightSizing of a child.

public static readonly BindableProperty HeightSizingProperty

Field Value

BindableProperty

HorizontalBiasProperty

Attached (set-only): HorizontalBias of a child.

public static readonly BindableProperty HorizontalBiasProperty

Field Value

BindableProperty

HorizontallyWithinProperty

Attached shortcut (set-only): left and right anchored to the target (positioned by HorizontalBias).

public static readonly BindableProperty HorizontallyWithinProperty

Field Value

BindableProperty

LeftToProperty

Attached (set-only): LeftTo of a child.

public static readonly BindableProperty LeftToProperty

Field Value

BindableProperty

MagnetIdProperty

Attached property: the MagnetId of a child.

public static readonly BindableProperty MagnetIdProperty

Field Value

BindableProperty

PropagateMagnetIdToAutomationIdProperty

Bindable property for PropagateMagnetIdToAutomationId.

public static readonly BindableProperty PropagateMagnetIdToAutomationIdProperty

Field Value

BindableProperty

RightToProperty

Attached (set-only): RightTo of a child.

public static readonly BindableProperty RightToProperty

Field Value

BindableProperty

TopToProperty

Attached (set-only): TopTo of a child.

public static readonly BindableProperty TopToProperty

Field Value

BindableProperty

VerticalBiasProperty

Attached (set-only): VerticalBias of a child.

public static readonly BindableProperty VerticalBiasProperty

Field Value

BindableProperty

VerticallyWithinProperty

Attached shortcut (set-only): top and bottom anchored to the target (positioned by VerticalBias).

public static readonly BindableProperty VerticallyWithinProperty

Field Value

BindableProperty

WidthSizingProperty

Attached (set-only): WidthSizing of a child.

public static readonly BindableProperty WidthSizingProperty

Field Value

BindableProperty

WithinProperty

Attached shortcut (set-only): all sides anchored to the target (positioned by the biases).

public static readonly BindableProperty WithinProperty

Field Value

BindableProperty

Properties

CompilationCacheCapacity

Gets or sets the maximum number of compiled layout structures kept in the process-wide cache. Defaults to 64.

public static int CompilationCacheCapacity { get; set; }

Property Value

int

Remarks

Structurally identical definitions (e.g. template-instantiated cells) share one compiled entry, so the capacity counts distinct structures, not instances. It is a safety net against unbounded growth rather than a tuning knob: an evicted structure is transparently recompiled in a few tens of microseconds. Shrinking trims the least recently used entries immediately; 0 disables caching.

Definition

Gets or sets the definition holding virtual nodes and (optionally) view constraints. Created lazily when not assigned.

public MagnetDefinition? Definition { get; set; }

Property Value

MagnetDefinition

IsTransitioning

Gets whether a transition is running.

public bool IsTransitioning { get; }

Property Value

bool

PropagateMagnetIdToAutomationId

Gets or sets whether the MagnetId of a child is copied to its AutomationId when the latter is not set. Defaults to true.

public bool PropagateMagnetIdToAutomationId { get; set; }

Property Value

bool

Methods

CreateLayoutManager()

Creates a manager object that can measure this layout and arrange its children.

protected override ILayoutManager CreateLayoutManager()

Returns

ILayoutManager

An object that implements ILayoutManager that manages this layout.

GetConstraints(BindableObject)

Gets the inline constraints node of a view, creating it on first access.

public static MagnetView GetConstraints(BindableObject view)

Parameters

view BindableObject

Returns

MagnetView

GetMagnetId(BindableObject)

Gets the MagnetId attached property (the inline node's id when one exists).

public static string? GetMagnetId(BindableObject view)

Parameters

view BindableObject

Returns

string

OnAdd(int, IView)

Invoked when Add(IView) is called and notifies the handler associated to this layout.

protected override void OnAdd(int index, IView view)

Parameters

index int

The index at which the child view was inserted.

view IView

The child view which was inserted.

OnApplyVisibilityRequested(MagnetView)

Entry point of ApplyVisibility: inside a TransitionToAsync(Action, uint, Easing?) mutate the write is collected (deferred and animated), otherwise it is stamped immediately.

public void OnApplyVisibilityRequested(MagnetView node)

Parameters

node MagnetView

OnClear()

Invoked when Clear() is called and notifies the handler associated to this layout.

protected override void OnClear()

OnInsert(int, IView)

Invoked when RemoveAt(int) is called and notifies the handler associated to this layout.

protected override void OnInsert(int index, IView view)

Parameters

index int

The index at which the child view was removed.

view IView

The child view which was removed.

OnRemove(int, IView)

Invoked when Insert(int, IView) is called and notifies the handler associated to this layout.

protected override void OnRemove(int index, IView view)

Parameters

index int

The index at which the child view was inserted.

view IView

The child view which was inserted.

OnUpdate(int, IView, IView)

Invoked when this[int] is called and notifies the handler associated to this layout.

protected override void OnUpdate(int index, IView view, IView oldView)

Parameters

index int

The index at which the child view was updated.

view IView

The new child view which was added at index.

oldView IView

The previous child view which was at index.

SetAbove(BindableObject, MagnetTarget?)

Sets the Above attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetAbove(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetAfter(BindableObject, MagnetTarget?)

Sets the After attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetAfter(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetAlignBottom(BindableObject, MagnetTarget?)

Sets the AlignBottom attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetAlignBottom(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetAlignLeft(BindableObject, MagnetTarget?)

Sets the AlignLeft attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetAlignLeft(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetAlignRight(BindableObject, MagnetTarget?)

Sets the AlignRight attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetAlignRight(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetAlignTop(BindableObject, MagnetTarget?)

Sets the AlignTop attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetAlignTop(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetBefore(BindableObject, MagnetTarget?)

Sets the Before attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetBefore(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetBelow(BindableObject, MagnetTarget?)

Sets the Below attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetBelow(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetBottomTo(BindableObject, MagnetAnchor?)

Sets the BottomTo attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetBottomTo(BindableObject view, MagnetAnchor? value)

Parameters

view BindableObject
value MagnetAnchor?

SetFillHeight(BindableObject, MagnetTarget?)

Sets the FillHeight attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetFillHeight(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetFillWidth(BindableObject, MagnetTarget?)

Sets the FillWidth attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetFillWidth(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetHeightSizing(BindableObject, MagnetSizing)

Sets the HeightSizing attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetHeightSizing(BindableObject view, MagnetSizing value)

Parameters

view BindableObject
value MagnetSizing

SetHorizontalBias(BindableObject, double)

Sets the HorizontalBias attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetHorizontalBias(BindableObject view, double value)

Parameters

view BindableObject
value double

SetHorizontallyWithin(BindableObject, MagnetTarget?)

Sets the HorizontallyWithin attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetHorizontallyWithin(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetLeftTo(BindableObject, MagnetAnchor?)

Sets the LeftTo attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetLeftTo(BindableObject view, MagnetAnchor? value)

Parameters

view BindableObject
value MagnetAnchor?

SetMagnetId(BindableObject, string?)

Sets the MagnetId attached property.

public static void SetMagnetId(BindableObject view, string? value)

Parameters

view BindableObject
value string

SetRightTo(BindableObject, MagnetAnchor?)

Sets the RightTo attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetRightTo(BindableObject view, MagnetAnchor? value)

Parameters

view BindableObject
value MagnetAnchor?

SetTopTo(BindableObject, MagnetAnchor?)

Sets the TopTo attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetTopTo(BindableObject view, MagnetAnchor? value)

Parameters

view BindableObject
value MagnetAnchor?

SetVerticalBias(BindableObject, double)

Sets the VerticalBias attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetVerticalBias(BindableObject view, double value)

Parameters

view BindableObject
value double

SetVerticallyWithin(BindableObject, MagnetTarget?)

Sets the VerticallyWithin attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetVerticallyWithin(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

SetWidthSizing(BindableObject, MagnetSizing)

Sets the WidthSizing attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetWidthSizing(BindableObject view, MagnetSizing value)

Parameters

view BindableObject
value MagnetSizing

SetWithin(BindableObject, MagnetTarget?)

Sets the Within attached property (set-only: read the node via GetConstraints(BindableObject)).

public static void SetWithin(BindableObject view, MagnetTarget? value)

Parameters

view BindableObject
value MagnetTarget?

TransitionToAsync(MagnetDefinition, uint, Easing?)

Swaps to a whole new definition, animating nodes matched by MagnetId.

public Task<bool> TransitionToAsync(MagnetDefinition end, uint length = 250, Easing? easing = null)

Parameters

end MagnetDefinition
length uint
easing Easing

Returns

Task<bool>

TransitionToAsync(Action, uint, Easing?)

Applies mutate (which edits nodes, toggles view visibility and/or swaps the Definition) and animates from the current visual state to the resulting one.

public Task<bool> TransitionToAsync(Action mutate, uint length = 250, Easing? easing = null)

Parameters

mutate Action
length uint
easing Easing

Returns

Task<bool>

true when the transition completed, false when it was interrupted by a newer one.

Remarks

Value-only changes (margins, biases, sizes, percents, weights, guideline positions) are animated by interpolating the constraint inputs, so intermediate states obey the constraint semantics; structural changes interpolate frames.