summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Renderers/ContentPageRenderer.cs
blob: 714f41bc4b8fb8aa6795051b66c922ebc7e94836 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using EColor = ElmSharp.Color;

namespace Xamarin.Forms.Platform.Tizen
{
	/// <summary>
	/// Renderer of ContentPage.
	/// </summary>
	public class ContentPageRenderer : VisualElementRenderer<ContentPage>
	{
		/// <summary>
		/// Native control which holds the contents.
		/// </summary>
		Native.ContentPage _page;

		/// <summary>
		/// Default constructor.
		/// </summary>
		public ContentPageRenderer()
		{
			RegisterPropertyHandler(Page.BackgroundImageProperty, UpdateBackgroundImage);
			RegisterPropertyHandler(Page.TitleProperty, UpdateTitle);
		}

		protected override void OnElementChanged(ElementChangedEventArgs<ContentPage> e)
		{
			if (null == _page)
			{
				_page = new Native.ContentPage(Forms.Context.MainWindow);
				_page.LayoutUpdated += OnLayoutUpdated;
				SetNativeControl(_page);
			}
			base.OnElementChanged(e);
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing)
			{
				if (_page != null)
				{
					_page.LayoutUpdated -= OnLayoutUpdated;
				}
			}
			base.Dispose(disposing);
		}

		protected override void UpdateBackgroundColor(bool initialize)
		{
			if (initialize && Element.BackgroundColor.IsDefault)
				return;

			// base.UpdateBackgroundColor() is not called on purpose, we don't want the regular background setting
			if (Element.BackgroundColor.IsDefault || Element.BackgroundColor.A == 0)
				_page.Color = EColor.Transparent;
			else
				_page.Color = Element.BackgroundColor.ToNative();
		}

		protected override void UpdateLayout()
		{
			// empty on purpose
		}

		void UpdateBackgroundImage(bool initiaize)
		{
			if (initiaize && string.IsNullOrWhiteSpace(Element.BackgroundImage))
				return;

			if (string.IsNullOrWhiteSpace(Element.BackgroundImage))
				_page.File = null;
			else
				_page.File = ResourcePath.GetPath(Element.BackgroundImage);
		}

		void UpdateTitle()
		{
			_page.Title = Element.Title;
		}

		void OnLayoutUpdated(object sender, Native.LayoutEventArgs e)
		{
			DoLayout(e);
		}
	}
}