Skip to main content

Slider Binders

Binders for the Unity UI Slider component.


SliderValueBinder​

Binds the slider value (Slider.value).

InterfaceDescription
INumberBinderAccepts int, float, long, double
INumberReverseBinderSends changes back (events)

Inspector properties​

PropertyDescription
ConverterIConverter<float, float> (optional)

Loop protection​

A write from the ViewModel raises onValueChanged for the other listeners, but the binder does not send it back to the ViewModel. The value is clamped to the slider range; if the clamp changed it, the changed value is sent to the ViewModel.

Modes: OneWay, TwoWay, OneTime, OneWayToSource.

[ViewModel]
public partial class VolumeViewModel
{
[TwoWayBind] private float _volume; // 0.0 - 1.0
}

SliderMinMaxBinder​

Binds the slider minimum and maximum (Slider.minValue, Slider.maxValue).

InterfaceDescription
IBinder<Vector2>x = minValue, y = maxValue

An inverted range is logged and swapped, a non-finite one is logged and not applied.

SliderRangeMode​

Defines which part of min/max is updated:

ModeBehaviour
MinUpdates minValue only
MaxUpdates maxValue only
RangeUpdates both minValue and maxValue

Modes: OneWay, OneTime, OneWayToSource (TwoWay is not allowed).

[ViewModel]
public partial class DifficultyViewModel
{
[OneWayBind] private Vector2 _damageRange; // (min, max) for the slider
}

SliderMinMaxSwitcherBinder​

bool → one of two Vector2 values for min/max. Supports SliderRangeMode.

Modes: OneWay, OneTime.


SliderCommandBinder​

Binds an IRelayCommand<float> to Slider.onValueChanged. When the slider value changes it calls command.Execute(value).

Accepts numeric commands: IRelayCommand<int>, IRelayCommand<long>, IRelayCommand<float>, IRelayCommand<double>.

InteractableMode​

The reaction to CanExecute, as in ButtonCommandBinder:

ModeBehaviour
Interactableslider.interactable = canExecute
VisiblegameObject.SetActive(canExecute)
NoneIgnores it
CustomCalls ICanExecuteHandler.SetCanExecute(bool)

Parameterized variants​

BinderCommandExtra parameters
SliderCommandBinderIRelayCommand<float>—
SliderCommandBinder<T>IRelayCommand<float, T>1 parameter
SliderCommandBinder<T1, T2>IRelayCommand<float, T1, T2>2 parameters
SliderCommandBinder<T1, T2, T3>IRelayCommand<float, T1, T2, T3>3 parameters

The first command parameter is always the current slider value.

Modes: OneWay, OneTime.

[ViewModel]
public partial class AudioViewModel
{
[RelayCommand]
private void SetVolume(float value) { /* ... */ }
// → IRelayCommand<float> SetVolumeCommand
}

SliderToSourceMonoBinder​

A MonoBinder for OneWayToSource binding of the Slider as a component. Inherits ComponentToSourceMonoBinder<Slider>.


See also​