summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core/Cells/ViewCell.cs
blob: 1ed35c9da7b87e10a3d344a4a5cf22312a6035a5 (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
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Xamarin.Forms
{
	[ContentProperty("View")]
	public class ViewCell : Cell
	{
		ReadOnlyCollection<Element> _logicalChildren;

		View _view;

		public View View
		{
			get { return _view; }
			set
			{
				if (_view == value)
					return;

				OnPropertyChanging();

				if (_view != null)
				{
					OnChildRemoved(_view);
					_view.ComputedConstraint = LayoutConstraint.None;
				}

				_view = value;

				if (_view != null)
				{
					_view.ComputedConstraint = LayoutConstraint.Fixed;
					OnChildAdded(_view);
					_logicalChildren = new ReadOnlyCollection<Element>(new List<Element>(new[] { View }));
				}
				else
				{
					_logicalChildren = null;
				}

				OnPropertyChanged();
			}
		}

		internal override ReadOnlyCollection<Element> LogicalChildrenInternal => _logicalChildren ?? base.LogicalChildrenInternal;
	}
}