Description
Can't update the Maximum/Mnimum using binding
Becuase validateValue
|
public static readonly BindableProperty MinimumProperty = BindableProperty.Create("Minimum", typeof(double), typeof(Slider), 0d, validateValue: (bindable, value) => |
|
{ |
|
var slider = (Slider)bindable; |
|
return (double)value < slider.Maximum; |
|
}, coerceValue: (bindable, value) => |
|
public static readonly BindableProperty MaximumProperty = BindableProperty.Create("Maximum", typeof(double), typeof(Slider), 1d, validateValue: (bindable, value) => |
|
{ |
|
var slider = (Slider)bindable; |
|
return (double)value > slider.Minimum; |
validateValue make hard to update value, according to value, Value update order should be changed. like below
if (max > Minimum)
{
Maximum = max;
Minimum = min;
}
else
{
Minimum = min;
Maximum = max;
}
But it is impossible in binding
So, I propose remove validateValue handler and update coerceValue like below
public static readonly BindableProperty MinimumProperty = BindableProperty.Create("Minimum", typeof(double), typeof(Slider), 0d, BindingMode.OneWay, coerceValue: (bindable, value) =>
{
var slider = (Slider)bindable;
slider.Value = Math.Max((double)value, slider.Value);
return value;
}, propertyChanged:(bindable, oldValue, newValue) =>
{
var slider = (Slider)bindable;
slider.SetValueCore(MaximumProperty, Math.Max(slider.Maximum, (double)newValue));
});
public static readonly BindableProperty MaximumProperty = BindableProperty.Create("Maximum", typeof(double), typeof(Slider), 1d, BindingMode.OneWay, coerceValue: (bindable, value) =>
{
var slider = (Slider)bindable;
slider.Value = Math.Min((double)value, slider.Value);
return value;
}, propertyChanged:(bindable, oldvalue, newValue) =>
{
var slider = (Slider)bindable;
slider.SetValueCore(MinimumProperty, Math.Min(slider.Minimum, (double)newValue));
});
Steps to Reproduce
class RangeModel
{
public double Max { get; set; }
public double Min { get; set; }
}
Slider slider = new Slider();
slider.SetBinding(Slider.MaximumProperty, new Binding("Max"));
slider.SetBinding(Slider.MinimumProperty, new Binding("Min"));
slider.BindingContext = new RangeModel { Min = -100, Max = -1 }; // ArgumentException was thrown
Expected Behavior
Update Minimum and Maximum
Actual Behavior
ArgumentException was thrown (Value was an invalid value for Maximum)
Description
Can't update the Maximum/Mnimum using binding
Becuase validateValue
Xamarin.Forms/Xamarin.Forms.Core/Slider.cs
Lines 10 to 14 in 882bf07
Xamarin.Forms/Xamarin.Forms.Core/Slider.cs
Lines 21 to 24 in 882bf07
validateValuemake hard to update value, according to value, Value update order should be changed. like belowBut it is impossible in binding
So, I propose remove validateValue handler and update coerceValue like below
Steps to Reproduce
Expected Behavior
Update Minimum and Maximum
Actual Behavior
ArgumentException was thrown (Value was an invalid value for Maximum)