1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
using System;
using Xamarin.Forms.Platform;
namespace Xamarin.Forms
{
[RenderWith(typeof(_StepperRenderer))]
public class Stepper : View, IElementConfiguration<Stepper>
{
public static readonly BindableProperty MaximumProperty = BindableProperty.Create("Maximum", typeof(double), typeof(Stepper), 100.0, validateValue: (bindable, value) =>
{
var stepper = (Stepper)bindable;
return (double)value > stepper.Minimum;
}, coerceValue: (bindable, value) =>
{
var stepper = (Stepper)bindable;
stepper.Value = stepper.Value.Clamp(stepper.Minimum, (double)value);
return value;
});
public static readonly BindableProperty MinimumProperty = BindableProperty.Create("Minimum", typeof(double), typeof(Stepper), 0.0, validateValue: (bindable, value) =>
{
var stepper = (Stepper)bindable;
return (double)value < stepper.Maximum;
}, coerceValue: (bindable, value) =>
{
var stepper = (Stepper)bindable;
stepper.Value = stepper.Value.Clamp((double)value, stepper.Maximum);
return value;
});
public static readonly BindableProperty ValueProperty = BindableProperty.Create("Value", typeof(double), typeof(Stepper), 0.0, BindingMode.TwoWay, coerceValue: (bindable, value) =>
{
var stepper = (Stepper)bindable;
return ((double)value).Clamp(stepper.Minimum, stepper.Maximum);
}, propertyChanged: (bindable, oldValue, newValue) =>
{
var stepper = (Stepper)bindable;
EventHandler<ValueChangedEventArgs> eh = stepper.ValueChanged;
if (eh != null)
eh(stepper, new ValueChangedEventArgs((double)oldValue, (double)newValue));
});
public static readonly BindableProperty IncrementProperty = BindableProperty.Create("Increment", typeof(double), typeof(Stepper), 1.0);
readonly Lazy<PlatformConfigurationRegistry<Stepper>> _platformConfigurationRegistry;
public Stepper()
{
_platformConfigurationRegistry = new Lazy<PlatformConfigurationRegistry<Stepper>>(() => new PlatformConfigurationRegistry<Stepper>(this));
}
public Stepper(double min, double max, double val, double increment)
{
if (min >= max)
throw new ArgumentOutOfRangeException("min");
if (max > Minimum)
{
Maximum = max;
Minimum = min;
}
else
{
Minimum = min;
Maximum = max;
}
Value = val.Clamp(min, max);
Increment = increment;
}
public double Increment
{
get { return (double)GetValue(IncrementProperty); }
set { SetValue(IncrementProperty, value); }
}
public double Maximum
{
get { return (double)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
public double Minimum
{
get { return (double)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}
public double Value
{
get { return (double)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public event EventHandler<ValueChangedEventArgs> ValueChanged;
public IPlatformElementConfiguration<T, Stepper> On<T>() where T : IConfigPlatform
{
return _platformConfigurationRegistry.Value.On<T>();
}
}
}
|