summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.MacOS/Cells/ViewCellRenderer.cs
blob: 8b345181388b9694dad1f91041e28714bcd52498 (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
´╗┐using System.ComponentModel;
using AppKit;

// ReSharper disable UnusedParameter.Local

namespace Xamarin.Forms.Platform.MacOS
{
	public class ViewCellRenderer : CellRenderer
	{
		public override NSView GetCell(Cell item, NSView reusableView, NSTableView tv)
		{
			var viewCell = (ViewCell)item;

			var cell = reusableView as ViewCellNSView;
			if (cell == null)
				cell = new ViewCellNSView();
			else
				cell.ViewCell.PropertyChanged -= ViewCellPropertyChanged;

			viewCell.PropertyChanged += ViewCellPropertyChanged;
			cell.ViewCell = viewCell;

			SetRealCell(item, cell);

			WireUpForceUpdateSizeRequested(item, cell, tv);

			UpdateBackground(cell, item);
			UpdateIsEnabled(cell, viewCell);
			return cell;
		}

		static void UpdateIsEnabled(ViewCellNSView cell, ViewCell viewCell)
		{
			//TODO: Implement IsEnabled on ViewCell
		}

		static void ViewCellPropertyChanged(object sender, PropertyChangedEventArgs e)
		{
			var viewCell = (ViewCell)sender;
			var realCell = (ViewCellNSView)GetRealCell(viewCell);

			if (e.PropertyName == Cell.IsEnabledProperty.PropertyName)
				UpdateIsEnabled(realCell, viewCell);
		}
	}
}