summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WP8/ActivityIndicatorRenderer.cs
blob: 0e0ceb61fdba0b0813ed8019405c6427e0e361c3 (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
´╗┐using System.ComponentModel;

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

			SetNativeControl(new System.Windows.Controls.ProgressBar());

			Control.IsIndeterminate = Element.IsRunning;
			UpdateColor();
		}

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

			if (e.PropertyName == ActivityIndicator.IsRunningProperty.PropertyName)
				Control.IsIndeterminate = Element.IsRunning;
			else if (e.PropertyName == ActivityIndicator.ColorProperty.PropertyName)
				UpdateColor();
		}

		void UpdateColor()
		{
			Color color = Element.Color;
			if (color == Color.Default)
				Control.ClearValue(System.Windows.Controls.Control.ForegroundProperty);
			else
				Control.Foreground = color.ToBrush();
		}
	}
}