Table of Contents

Class Slider

Namespace
Icy.UI.Controls
Assembly
IcyUI.dll

A horizontal slider - drag the thumb (or tap the track) to set Value between Minimum and Maximum.

public class Slider : Control, INotifyPropertyChanging, IBindingTarget, INotifyPropertyChanged, INotifyFocusChanged, IContainerLayout
Inheritance
Slider
Implements
Inherited Members
Extension Methods

Remarks

Thumb-grab is via OnDragStarted(Point)/OnDragPerforming(Point) - Canvas hit-tests once at drag-start and routes the rest of the sequence to whatever was hit there, regardless of where the cursor moves next (see Canvas's drag routing), so dragging below/above the track still works once a drag has started on the slider.

Template-safe via a named template part: a Template that declares an element named PART_Thumb (of any type assignable to Border) has its drag logic wired to that element instead of the built-in default thumb - see OnApplyTemplate(). A template that declares none still applies (the default thumb keeps working, just detached from what's visually shown - dragging silently does nothing until the template provides a real PART_Thumb).

Constructors

Slider()

Initializes a new instance of the Slider class.

public Slider()

Properties

Maximum

Gets or sets the value Value can reach at the right end of the track.

public float Maximum { get; set; }

Property Value

float

Minimum

Gets or sets the value Value can reach at the left end of the track.

public float Minimum { get; set; }

Property Value

float

ThumbBrush

Gets or sets the brush used to paint the thumb - the currently-live one (the default built-in thumb, or a Template's own PART_Thumb once OnApplyTemplate() has repointed thumb to it).

public IBrush ThumbBrush { get; set; }

Property Value

IBrush

Value

Gets or sets the current value, clamped to Minimum/Maximum.

[BindingOverride(BindingMode.TwoWay)]
public float Value { get; set; }

Property Value

float

Methods

ArrangeContent()

Handles custom arrange logic when overridden in any UIElement instance.

protected override void ArrangeContent()

Remarks

This method is called during the arrange pass to position and size the element's content within its final bounds. The element's position and size are already determined by the layout system and available in the ActualBounds property.

When implementing this method:

  • Position child elements within the available space;
  • Respect the element's padding when positioning content;
  • Handle any content-specific layout requirements;
  • Call Arrange() on child elements if needed.

GetDragAxes(in DragClaimContext)

Returns the axes along which this element wants to own a drag that starts on it or a descendant.

protected override DragAxes GetDragAxes(in DragClaimContext context)

Parameters

context DragClaimContext

The starting drag.

Returns

DragAxes

The claimed axes; the base implementation returns None.

Remarks

When a drag starts, Canvas asks the hit element and each ancestor in turn. The innermost element whose answer contains the drag's main axis (the larger component of LocalDirection) owns the gesture. If none does, the innermost element with any answer owns it. Only the owner receives OnDragStarted(Point), OnDragPerforming(Point), OnDragFling(Vector2) and OnDragEnded(Point).

An element that handles drags must override this method: overriding OnDragStarted(Point) alone receives nothing.

MeasureContent()

Handles custom measure logic when overridden in any UIElement instance.

protected override Size MeasureContent()

Returns

Size

Size recommended to display the UIElement.

Remarks

This method is called during the measure pass to determine the desired size of the element. The returned size should represent the natural size of the element's content, without considering any constraints, margins, or padding.

When implementing this method:

  • Return the natural size needed to display the content;
  • Do not include padding, margins, or borders in the returned size;
  • Consider the content's actual dimensions (e.g., text length, image size);
  • Return Empty if the element has no content.

OnApplyTemplate()

Called once, every time Template changes (in either direction - applied, cleared, or switched to a different template), right after Chrome and every decoration/content property have been fully re-wired for the new state.

protected override void OnApplyTemplate()

Remarks

Does nothing by default. A subclass that reaches into its own visual tree by reference - e.g. Slider wiring its drag logic directly to its thumb element - overrides this to call GetTemplateChild<T>(string) and repoint that reference to whatever the new Template (or, when reverting, the fresh default Border) actually provides, instead of hardcoding it once at construction. This is what actually makes a control "template-safe": until a control overrides this appropriately, applying a custom Template to it silently orphans whatever elements its own code still holds direct references to.

OnDragEnded(Point)

Invoked by Canvas when a drag sequence owned by this element (see GetDragAxes(in DragClaimContext)) has ended - released or canceled. The base implementation does nothing.

protected override void OnDragEnded(Point screenPoint)

Parameters

screenPoint Point

The drag's ending position, in screen/window space.

OnDragPerforming(Point)

Invoked by Canvas whenever the pointer moves during a drag sequence owned by this element (see GetDragAxes(in DragClaimContext)). The base implementation does nothing.

protected override void OnDragPerforming(Point screenPoint)

Parameters

screenPoint Point

The drag's current position, in screen/window space.

OnDragStarted(Point)

Invoked by Canvas when a drag sequence starts and this element owns it (see GetDragAxes(in DragClaimContext); overriding this method alone receives nothing). The base implementation does nothing.

protected override void OnDragStarted(Point screenPoint)

Parameters

screenPoint Point

The drag's starting position, in screen/window space.

Events

ValueChanged

Occurs when Value changes.

public event EventHandler? ValueChanged

Event Type

EventHandler