summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.WinRT/ActivityIndicatorRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.WinRT/ActivityIndicatorRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.WinRT/ActivityIndicatorRenderer.cs68
1 files changed, 68 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.WinRT/ActivityIndicatorRenderer.cs b/Xamarin.Forms.Platform.WinRT/ActivityIndicatorRenderer.cs
new file mode 100644
index 00000000..5c36afda
--- /dev/null
+++ b/Xamarin.Forms.Platform.WinRT/ActivityIndicatorRenderer.cs
@@ -0,0 +1,68 @@
+´╗┐using System.ComponentModel;
+using Windows.UI.Xaml;
+
+#if WINDOWS_UWP
+
+namespace Xamarin.Forms.Platform.UWP
+#else
+
+namespace Xamarin.Forms.Platform.WinRT
+#endif
+{
+ public class ActivityIndicatorRenderer : ViewRenderer<ActivityIndicator, Windows.UI.Xaml.Controls.ProgressBar>
+ {
+ object _foregroundDefault;
+
+ protected override void OnElementChanged(ElementChangedEventArgs<ActivityIndicator> e)
+ {
+ base.OnElementChanged(e);
+
+ if (e.NewElement != null)
+ {
+ if (Control == null)
+ {
+ SetNativeControl(new Windows.UI.Xaml.Controls.ProgressBar { IsIndeterminate = true });
+
+ Control.Loaded += OnControlLoaded;
+ }
+
+ // UpdateColor() called when loaded to ensure we can cache dynamic default colors
+ UpdateIsRunning();
+ }
+ }
+
+ protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ base.OnElementPropertyChanged(sender, e);
+
+ if (e.PropertyName == ActivityIndicator.IsRunningProperty.PropertyName)
+ UpdateIsRunning();
+ else if (e.PropertyName == ActivityIndicator.ColorProperty.PropertyName)
+ UpdateColor();
+ }
+
+ void OnControlLoaded(object sender, RoutedEventArgs routedEventArgs)
+ {
+ _foregroundDefault = Control.GetForegroundCache();
+ UpdateColor();
+ }
+
+ void UpdateColor()
+ {
+ Color color = Element.Color;
+ if (color.IsDefault)
+ {
+ Control.RestoreForegroundCache(_foregroundDefault);
+ }
+ else
+ {
+ Control.Foreground = color.ToBrush();
+ }
+ }
+
+ void UpdateIsRunning()
+ {
+ Opacity = Element.IsRunning ? 1 : 0;
+ }
+ }
+} \ No newline at end of file