summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/SliderRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.WinRT/SliderRenderer.cs59
1 files changed, 59 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs b/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs
new file mode 100644
index 00000000..ee7a8adc
--- /dev/null
+++ b/Xamarin.Forms.Platform.WinRT/SliderRenderer.cs
@@ -0,0 +1,59 @@
+´╗┐using System;
+using System.ComponentModel;
+using Windows.UI.Xaml.Controls.Primitives;
+
+#if WINDOWS_UWP
+
+namespace Xamarin.Forms.Platform.UWP
+#else
+
+namespace Xamarin.Forms.Platform.WinRT
+#endif
+{
+ public class SliderRenderer : ViewRenderer<Slider, Windows.UI.Xaml.Controls.Slider>
+ {
+ protected override void OnElementChanged(ElementChangedEventArgs<Slider> e)
+ {
+ base.OnElementChanged(e);
+
+ if (e.NewElement != null)
+ {
+ if (Control == null)
+ {
+ var slider = new Windows.UI.Xaml.Controls.Slider();
+ SetNativeControl(slider);
+
+ slider.ValueChanged += OnNativeValueCHanged;
+ }
+
+ double stepping = Math.Min((e.NewElement.Maximum - e.NewElement.Minimum) / 10, 1);
+ Control.StepFrequency = stepping;
+ Control.SmallChange = stepping;
+
+ Control.Minimum = e.NewElement.Minimum;
+ Control.Maximum = e.NewElement.Maximum;
+ Control.Value = e.NewElement.Value;
+ }
+ }
+
+ protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ base.OnElementPropertyChanged(sender, e);
+
+ if (e.PropertyName == Slider.MinimumProperty.PropertyName)
+ Control.Minimum = Element.Minimum;
+ else if (e.PropertyName == Slider.MaximumProperty.PropertyName)
+ Control.Maximum = Element.Maximum;
+ else if (e.PropertyName == Slider.ValueProperty.PropertyName)
+ {
+ if (Control.Value != Element.Value)
+ Control.Value = Element.Value;
+ }
+ }
+
+ void OnNativeValueCHanged(object sender, RangeBaseValueChangedEventArgs e)
+ {
+ ((IElementController)Element).SetValueFromRenderer(Slider.ValueProperty, e.NewValue);
+ }
+ }
+} \ No newline at end of file