maui-linux/Xamarin.Forms.Platform.UAP/ActivityIndicatorRenderer.cs

63 строки
1.6 KiB
C#
Исходник Обычный вид История

using System.ComponentModel;
2016-03-22 23:02:25 +03:00
using Windows.UI.Xaml;
namespace Xamarin.Forms.Platform.UWP
{
public class ActivityIndicatorRenderer : ViewRenderer<ActivityIndicator, FormsProgressBar>
2016-03-22 23:02:25 +03:00
{
object _foregroundDefault;
protected override void OnElementChanged(ElementChangedEventArgs<ActivityIndicator> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
if (Control == null)
{
SetNativeControl(new FormsProgressBar { IsIndeterminate = true, Style = Windows.UI.Xaml.Application.Current.Resources["FormsProgressBarStyle"] as Windows.UI.Xaml.Style });
2016-03-22 23:02:25 +03:00
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 || e.PropertyName == VisualElement.OpacityProperty.PropertyName)
2016-03-22 23:02:25 +03:00
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;
2016-03-22 23:02:25 +03:00
if (color.IsDefault)
{
Control.RestoreForegroundCache(_foregroundDefault);
}
else
{
Control.Foreground = color.ToBrush();
}
}
void UpdateIsRunning()
{
Control.ElementOpacity = Element.IsRunning ? Element.Opacity : 0;
2016-03-22 23:02:25 +03:00
}
}
}