summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS/NativeViewPropertyListener.cs
blob: ffe117f40d0318e0ff1d0201d0361b40863ce2a6 (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
using System;
using System.ComponentModel;
#if __UNIFIED__
using Foundation;

#else
using MonoTouch.Foundation;
#endif

namespace Xamarin.Forms.Platform.iOS
{
	class NativeViewPropertyListener : NSObject, INotifyPropertyChanged
	{
		string TargetProperty { get; set; }

		public NativeViewPropertyListener(string targetProperty)
		{
			TargetProperty = targetProperty;
		}

		public event PropertyChangedEventHandler PropertyChanged;

		public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
		{
			if (keyPath == TargetProperty)
				PropertyChanged?.Invoke(ofObject, new PropertyChangedEventArgs(TargetProperty));
		}
	}
}