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
AfterProperty
Attached shortcut (set-only): LeftTo = target.Right — "avatar,12", "avatar,12,gone:0".
public static readonly BindableProperty AfterProperty
Field Value
AlignBottomProperty
Attached shortcut (set-only): BottomTo = target.Bottom.
public static readonly BindableProperty AlignBottomProperty
Field Value
AlignLeftProperty
Attached shortcut (set-only): LeftTo = target.Left.
public static readonly BindableProperty AlignLeftProperty
Field Value
AlignRightProperty
Attached shortcut (set-only): RightTo = target.Right.
public static readonly BindableProperty AlignRightProperty
Field Value
AlignTopProperty
Attached shortcut (set-only): TopTo = target.Top.
public static readonly BindableProperty AlignTopProperty
Field Value
BeforeProperty
Attached shortcut (set-only): RightTo = target.Left.
public static readonly BindableProperty BeforeProperty
Field Value
BelowProperty
Attached shortcut (set-only): TopTo = target.Bottom.
public static readonly BindableProperty BelowProperty
Field Value
BottomToProperty
Attached (set-only): BottomTo of a child.
public static readonly BindableProperty BottomToProperty
Field Value
ConstraintsProperty
Attached property holding the inline MagnetView of a child (created lazily by GetConstraints(BindableObject)).
public static readonly BindableProperty ConstraintsProperty
Field Value
DefinitionProperty
Bindable property for Definition.
public static readonly BindableProperty DefinitionProperty
Field Value
FillHeightProperty
Attached shortcut (set-only): top and bottom anchored to the target and HeightSizing="*".
public static readonly BindableProperty FillHeightProperty
Field Value
FillWidthProperty
Attached shortcut (set-only): left and right anchored to the target and WidthSizing="*".
public static readonly BindableProperty FillWidthProperty
Field Value
HeightSizingProperty
Attached (set-only): HeightSizing of a child.
public static readonly BindableProperty HeightSizingProperty
Field Value
HorizontalBiasProperty
Attached (set-only): HorizontalBias of a child.
public static readonly BindableProperty HorizontalBiasProperty
Field Value
HorizontallyWithinProperty
Attached shortcut (set-only): left and right anchored to the target (positioned by HorizontalBias).
public static readonly BindableProperty HorizontallyWithinProperty
Field Value
LeftToProperty
Attached (set-only): LeftTo of a child.
public static readonly BindableProperty LeftToProperty
Field Value
MagnetIdProperty
Attached property: the MagnetId of a child.
public static readonly BindableProperty MagnetIdProperty
Field Value
PropagateMagnetIdToAutomationIdProperty
Bindable property for PropagateMagnetIdToAutomationId.
public static readonly BindableProperty PropagateMagnetIdToAutomationIdProperty
Field Value
RightToProperty
Attached (set-only): RightTo of a child.
public static readonly BindableProperty RightToProperty
Field Value
TopToProperty
Attached (set-only): TopTo of a child.
public static readonly BindableProperty TopToProperty
Field Value
VerticalBiasProperty
Attached (set-only): VerticalBias of a child.
public static readonly BindableProperty VerticalBiasProperty
Field Value
VerticallyWithinProperty
Attached shortcut (set-only): top and bottom anchored to the target (positioned by VerticalBias).
public static readonly BindableProperty VerticallyWithinProperty
Field Value
WidthSizingProperty
Attached (set-only): WidthSizing of a child.
public static readonly BindableProperty WidthSizingProperty
Field Value
WithinProperty
Attached shortcut (set-only): all sides anchored to the target (positioned by the biases).
public static readonly BindableProperty WithinProperty
Field Value
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
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
IsTransitioning
Gets whether a transition is running.
public bool IsTransitioning { get; }
Property Value
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
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
viewBindableObject
Returns
GetMagnetId(BindableObject)
Gets the MagnetId attached property (the inline node's id when one exists).
public static string? GetMagnetId(BindableObject view)
Parameters
viewBindableObject
Returns
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
indexintThe index at which the child view was inserted.
viewIViewThe 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
nodeMagnetView
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
indexintThe index at which the child view was removed.
viewIViewThe 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
indexintThe index at which the child view was inserted.
viewIViewThe 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
indexintThe index at which the child view was updated.
viewIViewThe new child view which was added at
index.oldViewIViewThe 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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetAnchor?
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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetSizing
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
viewBindableObjectvaluedouble
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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetAnchor?
SetMagnetId(BindableObject, string?)
Sets the MagnetId attached property.
public static void SetMagnetId(BindableObject view, string? value)
Parameters
viewBindableObjectvaluestring
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
viewBindableObjectvalueMagnetAnchor?
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
viewBindableObjectvalueMagnetAnchor?
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
viewBindableObjectvaluedouble
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
viewBindableObjectvalueMagnetTarget?
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
viewBindableObjectvalueMagnetSizing
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
viewBindableObjectvalueMagnetTarget?
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
endMagnetDefinitionlengthuinteasingEasing
Returns
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
Returns
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.