-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathNumericUpDown.xaml.cs
59 lines (50 loc) · 1.63 KB
/
NumericUpDown.xaml.cs
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
namespace MauiConditionView;
using System.Globalization;
public partial class NumericUpDown
{
public NumericUpDown()
{
InitializeComponent();
ValueControl.Text = Value.ToString(CultureInfo.CurrentCulture);
}
public static readonly BindableProperty ValueProperty = BindableProperty.Create(nameof(Value), typeof(double), typeof(NumericUpDown), 0.0, BindingMode.TwoWay);
public static readonly BindableProperty MinimumProperty = BindableProperty.Create(nameof(Minimum), typeof(double), typeof(NumericUpDown), 0.0);
public static readonly BindableProperty MaximumProperty = BindableProperty.Create(nameof(Maximum), typeof(double), typeof(NumericUpDown), 100.0);
public static readonly BindableProperty IncrementProperty = BindableProperty.Create(nameof(Increment), typeof(double), typeof(NumericUpDown), 1.0);
public double Value
{
get => (double)GetValue(ValueProperty);
set
{
var newValue = Math.Clamp(value, Minimum, Maximum);
if (!newValue.Equals((double)GetValue(ValueProperty)))
{
SetValue(ValueProperty, newValue);
ValueControl.Text = newValue.ToString(CultureInfo.CurrentCulture);
}
}
}
public double Minimum
{
get => (double)GetValue(MinimumProperty);
set => SetValue(MinimumProperty, value);
}
public double Maximum
{
get => (double)GetValue(MaximumProperty);
set => SetValue(MaximumProperty, value);
}
public double Increment
{
get => (double)GetValue(IncrementProperty);
set => SetValue(IncrementProperty, value);
}
private void IncrementClicked(object sender, EventArgs e)
{
Value += Increment;
}
private void DecrementClicked(object sender, EventArgs e)
{
Value -= Increment;
}
}