Support to change color on Slider for tizen backend (#2072)

This commit is contained in:
Kangho 2018-03-12 17:42:11 +09:00 коммит произвёл Stephane Delcroix
Родитель 1df63c27b9
Коммит 4e902c67b4
1 изменённых файлов: 48 добавлений и 0 удалений

Просмотреть файл

@ -2,11 +2,16 @@ using System;
using System.ComponentModel;
using ESlider = ElmSharp.Slider;
using ESize = ElmSharp.Size;
using EColor = ElmSharp.Color;
namespace Xamarin.Forms.Platform.Tizen
{
public class SliderRenderer : ViewRenderer<Slider, ESlider>
{
EColor _defaultMinColor;
EColor _defaultMaxColor;
EColor _defaultThumbColor;
protected override void OnElementChanged(ElementChangedEventArgs<Slider> e)
{
if (Control == null)
@ -16,10 +21,14 @@ namespace Xamarin.Forms.Platform.Tizen
PropagateEvents = false,
});
Control.ValueChanged += OnValueChanged;
_defaultMinColor = Control.GetPartColor("bar");
_defaultMaxColor = Control.GetPartColor("bg");
_defaultThumbColor = Control.GetPartColor("handler");
}
UpdateMinimum();
UpdateMaximum();
UpdateValue();
UpdateSliderColors();
base.OnElementChanged(e);
}
@ -37,6 +46,18 @@ namespace Xamarin.Forms.Platform.Tizen
{
UpdateValue();
}
else if (e.PropertyName == Slider.MinimumTrackColorProperty.PropertyName)
{
UpdateMinimumTrackColor();
}
else if (e.PropertyName == Slider.MaximumTrackColorProperty.PropertyName)
{
UpdateMaximumTrackColor();
}
else if (e.PropertyName == Slider.ThumbColorProperty.PropertyName)
{
UpdateThumbColor();
}
base.OnElementPropertyChanged(sender, e);
}
@ -76,5 +97,32 @@ namespace Xamarin.Forms.Platform.Tizen
{
Control.Maximum = Element.Maximum;
}
protected void UpdateMinimumTrackColor()
{
var color = Element.MinimumTrackColor.IsDefault ? _defaultMinColor : Element.MinimumTrackColor.ToNative();
Control.SetPartColor("bar", color);
Control.SetPartColor("bar_pressed", color);
}
protected void UpdateMaximumTrackColor()
{
Control.SetPartColor("bg", Element.MaximumTrackColor.IsDefault ? _defaultMaxColor : Element.MaximumTrackColor.ToNative());
}
protected void UpdateThumbColor()
{
var color = Element.ThumbColor.IsDefault ? _defaultThumbColor : Element.ThumbColor.ToNative();
Control.SetPartColor("handler", color);
Control.SetPartColor("handler_pressed", color);
}
protected void UpdateSliderColors()
{
// Changing slider color is only available on mobile profile. Otherwise ignored.
UpdateMinimumTrackColor();
UpdateMaximum();
UpdateThumbColor();
}
}
}