summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/SliderRenderer.cs
blob: 40cd767df36ce8cb543a9423e82c8e03c922afcc (plain)
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
´╗┐using System.ComponentModel;
using System.Windows;

namespace Xamarin.Forms.Platform.WinPhone
{
	public class SliderRenderer : ViewRenderer<Slider, System.Windows.Controls.Slider>
	{
		protected override void OnElementChanged(ElementChangedEventArgs<Slider> e)
		{
			base.OnElementChanged(e);

			var wSlider = new System.Windows.Controls.Slider { Minimum = Element.Minimum, Maximum = Element.Maximum, Value = Element.Value };

			SetNativeControl(wSlider);

			wSlider.ValueChanged += HandleValueChanged;
		}

		protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			base.OnElementPropertyChanged(sender, e);

			switch (e.PropertyName)
			{
				case "Minimum":
					Control.Minimum = Element.Minimum;
					break;
				case "Maximum":
					Control.Maximum = Element.Maximum;
					break;
				case "Value":
					if (Control.Value != Element.Value)
						Control.Value = Element.Value;
					break;
			}
		}

		void HandleValueChanged(object sender, RoutedPropertyChangedEventArgs<double> routedPropertyChangedEventArgs)
		{
			((IElementController)Element).SetValueFromRenderer(Slider.ValueProperty, Control.Value);
		}
	}
}