summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Renderers/BoxViewRenderer.cs
blob: 7a9f756df64b97a66b1b17a57aa17bedae33db6c (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System.ComponentModel;
using EColor = ElmSharp.Color;
using ERectangle = ElmSharp.Rectangle;

namespace Xamarin.Forms.Platform.Tizen
{
	public class BoxViewRenderer :
	VisualElementRenderer<BoxView>
	{
		static readonly EColor s_defaultColor = EColor.Transparent;

		ERectangle _control;

		public BoxViewRenderer()
		{
		}

		protected override void OnElementChanged(ElementChangedEventArgs<BoxView> e)
		{
			if (_control == null)
			{
				_control = new ERectangle(Forms.Context.MainWindow);
				SetNativeControl(_control);
			}

			if (e.OldElement != null)
			{
			}

			if (e.NewElement != null)
			{
				UpdateColor();
			}

			base.OnElementChanged(e);
		}

		void UpdateColor()
		{
			Color colorToSet = Element.Color;

			if (colorToSet == Color.Default)
			{
				colorToSet = Element.BackgroundColor;
			}

			_control.Color = (colorToSet == Color.Default) ? s_defaultColor : colorToSet.ToNative();
		}

		protected override void OnElementPropertyChanged(object sender,
			PropertyChangedEventArgs e)
		{
			if (e.PropertyName == BoxView.ColorProperty.PropertyName ||
				e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName)
			{
				UpdateColor();
			}
			base.OnElementPropertyChanged(sender, e);
		}
	}
}