summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT/StepperControl.xaml.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/StepperControl.xaml.cs')
-rw-r--r--Xamarin.Forms.Platform.WinRT/StepperControl.xaml.cs94
1 files changed, 94 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/StepperControl.xaml.cs b/Xamarin.Forms.Platform.WinRT/StepperControl.xaml.cs
new file mode 100644
index 00000000..49a4632f
--- /dev/null
+++ b/Xamarin.Forms.Platform.WinRT/StepperControl.xaml.cs
@@ -0,0 +1,94 @@
+´╗┐using System;
+using Windows.UI.Xaml;
+using Windows.UI.Xaml.Controls;
+
+namespace Xamarin.Forms.Platform.WinRT
+{
+ public sealed partial class StepperControl : UserControl
+ {
+ public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(StepperControl), new PropertyMetadata(default(double), OnValueChanged));
+
+ public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register("Maximum", typeof(double), typeof(StepperControl), new PropertyMetadata(default(double), OnMaxMinChanged));
+
+ public static readonly DependencyProperty MinimumProperty = DependencyProperty.Register("Minimum", typeof(double), typeof(StepperControl), new PropertyMetadata(default(double), OnMaxMinChanged));
+
+ public static readonly DependencyProperty IncrementProperty = DependencyProperty.Register("Increment", typeof(double), typeof(StepperControl),
+ new PropertyMetadata(default(double), OnIncrementChanged));
+
+ public StepperControl()
+ {
+ InitializeComponent();
+ }
+
+ 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 ValueChanged;
+
+ static void OnIncrementChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var stepper = (StepperControl)d;
+ stepper.UpdateEnabled(stepper.Value);
+ }
+
+ static void OnMaxMinChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var stepper = (StepperControl)d;
+ stepper.UpdateEnabled(stepper.Value);
+ }
+
+ void OnMinusClicked(object sender, RoutedEventArgs e)
+ {
+ UpdateValue(-Increment);
+ }
+
+ void OnPlusClicked(object sender, RoutedEventArgs e)
+ {
+ UpdateValue(+Increment);
+ }
+
+ static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ var stepper = (StepperControl)d;
+ stepper.UpdateEnabled((double)e.NewValue);
+
+ EventHandler changed = stepper.ValueChanged;
+ if (changed != null)
+ changed(d, EventArgs.Empty);
+ }
+
+ void UpdateEnabled(double value)
+ {
+ double increment = Increment;
+ Plus.IsEnabled = value + increment <= Maximum;
+ Minus.IsEnabled = value - increment >= Minimum;
+ }
+
+ void UpdateValue(double delta)
+ {
+ double newValue = Value + delta;
+ Value = newValue;
+ }
+ }
+} \ No newline at end of file