summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Tizen/Native/TableView.cs
blob: 73388a84216dc647398b390f52e89cba717946c0 (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
using ElmSharp;

namespace Xamarin.Forms.Platform.Tizen.Native
{
	/// <summary>
	/// Extends the ListView class to provide TableView class implementation.
	/// </summary>
	public class TableView : ListView
	{

		static readonly SectionCellRenderer _sectionCellRenderer = new SectionCellRenderer();
		/// <summary>
		/// Initializes a new instance of the TableView class.
		/// </summary>
		public TableView(EvasObject parent)
			: base(parent) {
		}

		/// <summary>
		/// Sets the root of the table.
		/// </summary>
		/// <param name="root">TableRoot, which is parent to one or more TableSections.</param>
		public void ApplyTableRoot(TableRoot root)
		{
			Clear();
			foreach (TableSection ts in root)
			{
				AddSectionTitle(ts.Title);
				AddSource(ts);
			}
		}

		protected override CellRenderer GetCellRenderer(Cell cell, bool isGroup = false)
		{
			if (cell.GetType() == typeof(SectionCell))
			{
				return _sectionCellRenderer;
			}
			return base.GetCellRenderer(cell, isGroup);
		}

		/// <summary>
		/// Sets the section title.
		/// </summary>
		void AddSectionTitle(string title)
		{
			Cell cell = new SectionCell()
			{
				Text = title
			};
			AddCell(cell);
		}

		internal class SectionCellRenderer : GroupCellTextRenderer
		{
			public SectionCellRenderer()
			{
				DetailPart = "null";
			}
			protected SectionCellRenderer(string style) : base(style) { }
		}
		class SectionCell : TextCell
		{
		}
	}
}