/// <summary>
/// TrackThicknessProperty
- /// </summary>
+ /// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
{
/// <summary>
/// IsValueShownProperty
- /// </summary>
+ /// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty IsValueShownProperty = BindableProperty.Create(nameof(IsValueShown), typeof(bool), typeof(Slider), true, propertyChanged: (bindable, oldValue, newValue) =>
{
/// <summary>
/// ValueIndicatorTextProperty
- /// </summary>
+ /// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty ValueIndicatorTextProperty = BindableProperty.Create(nameof(ValueIndicatorText), typeof(string), typeof(Slider), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
{
}
}
+ /// <summary>
+ /// Flag to decide whether the thumb snap to the nearest discrete value when the user drags the thumb or taps.
+ ///
+ /// The default value is false.
+ /// </summary>
+ /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public bool IsDiscrete { get; set; } = false;
+
+ /// <summary>
+ /// Gets or sets the discrete value of slider.
+ ///
+ /// The discrete value is evenly spaced between MinValue and MaxValue.
+ /// For example, MinValue is 0, MaxValue is 100, and DiscreteValue is 20.
+ /// Then, the thumb can only go to 0, 20, 40, 60, 80, and 100.
+ /// The default is 0.
+ /// </summary>
+ /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public float DiscreteValue
+ {
+ get
+ {
+ return discreteValue;
+ }
+ set
+ {
+ discreteValue = value;
+ UpdateValue();
+ }
+ }
+
private Extents spaceBetweenTrackAndIndicator
{
get
curValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
}
}
+
+ if (IsDiscrete)
+ {
+ curValue = CalculateDiscreteValue(curValue);
+ }
+
if (valueChangedHandler != null)
{
ValueChangedArgs args = new ValueChangedArgs();
if (bgTrackLength != 0)
{
curValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
+
+ if (IsDiscrete)
+ {
+ curValue = CalculateDiscreteValue(curValue);
+ }
+
if (null != valueChangedHandler)
{
ValueChangedArgs args = new ValueChangedArgs();
}
}
+ private float CalculateDiscreteValue(float value)
+ {
+ return ((float)Math.Round((value / discreteValue)) * discreteValue);
+ }
+
private void UpdateState(bool isFocusedNew, bool isPressedNew)
{
if (isFocused == isFocusedNew && isPressed == isPressedNew)