summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Controls/ViewContainers/MultiBindingHack.cs
blob: 4853fd146ab00d4cbcd668410659012daf7cdb0e (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
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Xamarin.Forms.Controls
{
	[Preserve (AllMembers = true)]
	internal class MultiBindingHack : INotifyPropertyChanged
	{
		string _labelWithBounds;

		public MultiBindingHack (VisualElement element)
		{
			LabelWithBounds = string.Format("{{X={0:0.00} Y={1:0.00} Width={2:0.00} Height={3:0.00}}}", element.X, element.Y, element.Width, element.Height);

			element.PropertyChanged += (sender, args) => {
				if (args.PropertyName == "X" || 
					args.PropertyName == "Y" || 
					args.PropertyName == "Width" || 
					args.PropertyName == "Height" || 
					args.PropertyName == "Rotation") {
					LabelWithBounds = string.Format("{{X={0:0.00} Y={1:0.00} Width={2:0.00} Height={3:0.00}}}", element.X, element.Y, element.Width, element.Height); // super hack
				}
			};
		}

		public string LabelWithBounds
		{
			get { return _labelWithBounds; }
			set
			{
				if (_labelWithBounds == value)
					return;
				_labelWithBounds = value;
				OnPropertyChanged ();
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;

		void OnPropertyChanged ([CallerMemberName] string propertyName = null)
		{
			PropertyChangedEventHandler handler = PropertyChanged;
			if (handler != null)
				handler (this, new PropertyChangedEventArgs (propertyName));
		}
	}
}