Table of Contents

Class SkiaCarousel

Namespace
DrawnUi.Controls
Assembly
DrawnUi.Maui.dll

A specialized scroll control designed for creating swipeable carousels with automatic snapping to items. Supports data binding through ItemsSource and ItemTemplate, peek effects with SidesOffset, and smooth transitions. Ideal for image galleries, tab interfaces, and any swipeable content display.

public class SkiaCarousel : SnappingLayout, INotifyPropertyChanged, IEffectControlProvider, IToolTipElement, IContextFlyoutElement, IAnimatable, IVisualElementController, IElementController, IView, ITransform, IElement, IVisualTreeElement, IContainer, IList<IView>, ICollection<IView>, IEnumerable<IView>, IEnumerable, ISkiaGestureListener, IHasAfterEffects, ISkiaDisposable, ISkiaGridLayout, ISkiaLayout, ISkiaControl, IDrawnBase, ICanBeUpdatedWithContext, ICanBeUpdated, ILayoutInsideViewport, IInsideViewport, IVisibilityAware, IDisposable
Inheritance
SkiaCarousel
Implements
Inherited Members
Extension Methods

Constructors

SkiaCarousel()

public SkiaCarousel()

Fields

ChildrenInitialized

protected bool ChildrenInitialized

Field Value

bool

ChildrenTotalProperty

public static readonly BindableProperty ChildrenTotalProperty

Field Value

BindableProperty

DynamicSizeProperty

public static readonly BindableProperty DynamicSizeProperty

Field Value

BindableProperty

IsLoopedProperty

public static readonly BindableProperty IsLoopedProperty

Field Value

BindableProperty

IsRightToLeftProperty

public static readonly BindableProperty IsRightToLeftProperty

Field Value

BindableProperty

IsVerticalProperty

public static readonly BindableProperty IsVerticalProperty

Field Value

BindableProperty

LinearSpeedMsProperty

public static readonly BindableProperty LinearSpeedMsProperty

Field Value

BindableProperty

PreloadNeighboorsProperty

public static readonly BindableProperty PreloadNeighboorsProperty

Field Value

BindableProperty

SelectedIndexProperty

public static readonly BindableProperty SelectedIndexProperty

Field Value

BindableProperty

SidesOffsetProperty

public static readonly BindableProperty SidesOffsetProperty

Field Value

BindableProperty

SwipeSpeedProperty

public static readonly BindableProperty SwipeSpeedProperty

Field Value

BindableProperty

_panningOffset

protected Vector2 _panningOffset

Field Value

Vector2

_panningStartOffset

protected Vector2 _panningStartOffset

Field Value

Vector2

Properties

CanRender

protected virtual bool CanRender { get; }

Property Value

bool

CellSize

public ScaledSize CellSize { get; set; }

Property Value

ScaledSize

ChildrenCount

public int ChildrenCount { get; set; }

Property Value

int

ChildrenReady

protected virtual bool ChildrenReady { get; }

Property Value

bool

ChildrenTotal

Can be used for indicators

public int ChildrenTotal { get; set; }

Property Value

int

DynamicSize

When specific dimension is adapting to children size, will use max child dimension if False, otherwise will change size when children with different dimension size are selected. Default is false. If true, requires MeasureAllItems to be set to all items.

public bool DynamicSize { get; set; }

Property Value

bool

IsAtEnd

public virtual bool IsAtEnd { get; }

Property Value

bool

IsAtStart

public virtual bool IsAtStart { get; }

Property Value

bool

IsLooped

UNIMPLEMENTED YET

public bool IsLooped { get; set; }

Property Value

bool

IsRightToLeft

TODO

public bool IsRightToLeft { get; set; }

Property Value

bool

IsUserFocused

public bool IsUserFocused { get; protected set; }

Property Value

bool

IsUserPanning

public bool IsUserPanning { get; protected set; }

Property Value

bool

IsVertical

Orientation of the carousel

public bool IsVertical { get; set; }

Property Value

bool

ItemsVisibility

protected ConcurrentDictionary<int, bool> ItemsVisibility { get; }

Property Value

ConcurrentDictionary<int, bool>

LastIndex

public int LastIndex { get; set; }

Property Value

int

LastScrollProgress

protected double LastScrollProgress { get; set; }

Property Value

double

LinearSpeedMs

How long would a whole auto-sliding take, if Bounces is False. If set (>0) will be used for automatic scrolls instead of using manual velocity. For bouncing carousel

public double LinearSpeedMs { get; set; }

Property Value

double

MaxIndex

public int MaxIndex { get; set; }

Property Value

int

PreloadNeighboors

Whether should preload neighboors sides cells even when they are hidden, to preload images etc.. Default is true. Beware set this to False if you have complex layouts otherwise rendering might be slow.

public bool PreloadNeighboors { get; set; }

Property Value

bool

SafeIndex

Will be updated on MainThread to safely work with bindings, this a read-only property returning SelectingIndex in a thread-safe way;

public int SafeIndex { get; }

Property Value

int

ScrollAmount

Scroll amount from 0 to 1 of the current (SelectedIndex) slide. Another similar but different property would be ScrollProgress. This is not linear as SelectedIndex changes earlier than 0 or 1 are attained.

public double ScrollAmount { get; set; }

Property Value

double

ScrollProgress

Scroll progress from 0 to (numberOfSlides-1). This is not dependent of the SelectedIndex, just reflects visible progress. Useful to create custom controls attached to carousel. Calculated as (for horizontal): CurrentPosition.X / SnapPoints.Last().X

public double ScrollProgress { get; set; }

Property Value

double

SelectedIndex

Zero-based index of the currently selected slide

public int SelectedIndex { get; set; }

Property Value

int

SidesOffset

Basically size margins of every slide, offset from the side of the carousel. Another similar but different property to use would be Spacing between slides.

public double SidesOffset { get; set; }

Property Value

double

SnapPointsVirtual

protected List<SkiaCarousel.SnapPoint> SnapPointsVirtual { get; set; }

Property Value

List<SkiaCarousel.SnapPoint>

SwipeSpeed

Used inside ScrollToOffset to control the speed

public double SwipeSpeed { get; set; }

Property Value

double

TransitionProgress

public double TransitionProgress { get; }

Property Value

double

VelocityAccumulator

protected VelocityAccumulator VelocityAccumulator { get; }

Property Value

VelocityAccumulator

WillClipBounds

Used to check whether to apply IsClippedToBounds property

public override bool WillClipBounds { get; }

Property Value

bool

Methods

AdaptChildren()

Set children layout options according to our settings. Not used for template case.

protected virtual void AdaptChildren()

AdaptTemplate(SkiaControl)

protected void AdaptTemplate(SkiaControl skiaControl)

Parameters

skiaControl SkiaControl

AnimateVisibleChild(SkiaControl, Vector2)

protected virtual void AnimateVisibleChild(SkiaControl view, Vector2 position)

Parameters

view SkiaControl
position Vector2

ApplyDynamicSize(int)

protected virtual void ApplyDynamicSize(int index)

Parameters

index int

ApplyIndex(bool)

public virtual void ApplyIndex(bool instant = false)

Parameters

instant bool

ApplyOptions(bool)

public override void ApplyOptions(bool initialize)

Parameters

initialize bool

ApplyPosition(Vector2)

Will translate child and raise appearing/disappearing events

public override void ApplyPosition(Vector2 currentPosition)

Parameters

currentPosition Vector2

CalculateChildPosition(Vector2, int, int)

protected virtual (Vector2 Offset, bool OnScreen, bool NextToScreen) CalculateChildPosition(Vector2 currentPosition, int index, int childrenCount)

Parameters

currentPosition Vector2
index int
childrenCount int

Returns

(Vector2 Offset, bool OnScreen, bool NextToScreen)

CheckConstraints()

protected virtual void CheckConstraints()

CheckTransitionEnded()

public override bool CheckTransitionEnded()

Returns

bool

CreateContentFromTemplate()

public override object CreateContentFromTemplate()

Returns

object

FindNearestAnchorInternal(Vector2, Vector2)

protected override Vector2 FindNearestAnchorInternal(Vector2 current, Vector2 velocity)

Parameters

current Vector2
velocity Vector2

Returns

Vector2

FixIndex()

public virtual void FixIndex()

FixPosition()

Set true position if inside virtual for IsLooped

protected virtual void FixPosition()

GetContentOffsetBounds()

There are the bounds the scroll offset can go to.. This are NOT the bounds of the whole content.

public override SKRect GetContentOffsetBounds()

Returns

SKRect

GetTemplatesPoolLimit()

protected override int GetTemplatesPoolLimit()

Returns

int

GetTemplatesPoolPrefill()

protected override int GetTemplatesPoolPrefill()

Returns

int

GetVirtualAnchor(Vector2, Vector2)

protected virtual SkiaCarousel.SnapPoint GetVirtualAnchor(Vector2 current, Vector2 velocity)

Parameters

current Vector2
velocity Vector2

Returns

SkiaCarousel.SnapPoint

GetVirtualSnapPoints()

protected virtual List<SkiaCarousel.SnapPoint> GetVirtualSnapPoints()

Returns

List<SkiaCarousel.SnapPoint>

GoNext()

public void GoNext()

GoPrev()

public virtual void GoPrev()

InitializeChildren()

We expect this to be called after this alyout is invalidated

public virtual void InitializeChildren()

OnChildAdded(SkiaControl)

public override void OnChildAdded(SkiaControl child)

Parameters

child SkiaControl

OnChildrenInitialized()

protected virtual void OnChildrenInitialized()

OnDisposing()

Base performs some cleanup actions with Superview

public override void OnDisposing()

OnItemSourceChanged()

public override void OnItemSourceChanged()

OnLayoutChanged()

DrawingRect size changed

protected override void OnLayoutChanged()

OnScrollProgressChanged()

protected virtual void OnScrollProgressChanged()

OnSelectedIndexChanged(int)

protected virtual void OnSelectedIndexChanged(int index)

Parameters

index int

OnTemplatesAvailable()

This might be called from background thread if we set InitializeTemplatesInBackgroundDelay true

public override void OnTemplatesAvailable()

OnTransitionChanged()

Invokes TransitionChanged event

public override void OnTransitionChanged()

ProcessGestures(SkiaGesturesParameters, GestureEventProcessingInfo)

public override ISkiaGestureListener ProcessGestures(SkiaGesturesParameters args, GestureEventProcessingInfo apply)

Parameters

args SkiaGesturesParameters
apply GestureEventProcessingInfo

Returns

ISkiaGestureListener

RenderViewsList(DrawingContext, IEnumerable<SkiaControl>)

Use to render Absolute layout. Base method is not supporting templates, override it to implement your logic. Returns number of drawn children.

protected override int RenderViewsList(DrawingContext context, IEnumerable<SkiaControl> skiaControls)

Parameters

context DrawingContext
skiaControls IEnumerable<SkiaControl>

Returns

int

RenderVisibleChild(DrawingContext, SkiaControl, Vector2)

protected virtual void RenderVisibleChild(DrawingContext context, SkiaControl view, Vector2 position)

Parameters

context DrawingContext
view SkiaControl
position Vector2

ScrollToNearestAnchor(Vector2, Vector2)

public override void ScrollToNearestAnchor(Vector2 location, Vector2 velocity)

Parameters

location Vector2
velocity Vector2

ScrollToOffset(Vector2, Vector2, bool)

protected override bool ScrollToOffset(Vector2 targetOffset, Vector2 velocity, bool animate)

Parameters

targetOffset Vector2
velocity Vector2
animate bool

Returns

bool

SelectNextAnchor(Vector2, Vector2)

Return an anchor depending on direction and strength of of the velocity

public override Vector2 SelectNextAnchor(Vector2 origin, Vector2 velocity)

Parameters

origin Vector2
velocity Vector2

Returns

Vector2

SetupViewport()

protected void SetupViewport()

UpdateReportedPosition()

public override void UpdateReportedPosition()

Events

ItemAppearing

public event EventHandler<int> ItemAppearing

Event Type

EventHandler<int>

ItemDisappearing

public event EventHandler<int> ItemDisappearing

Event Type

EventHandler<int>

SelectedIndexChanged

public event EventHandler<int> SelectedIndexChanged

Event Type

EventHandler<int>

Stopped

public event EventHandler<Vector2> Stopped

Event Type

EventHandler<Vector2>