summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.MacOS/Controls/NavigationChildPageWrapper.cs
blob: a0e6dd41ebec32a347076c95d10ee1f808af57c9 (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
using System;
using Foundation;

namespace Xamarin.Forms.Platform.MacOS
{
	internal class NavigationChildPageWrapper : NSObject
	{
		bool _disposed;

		public NavigationChildPageWrapper(Page page)
		{
			Page = page;
			Page.PropertyChanged += PagePropertyChanged;
			Identifier = Guid.NewGuid().ToString();
		}

		protected override void Dispose(bool disposing)
		{
			if (disposing && !_disposed)
			{
				_disposed = true;
				if (Page != null)
					Page.PropertyChanged -= PagePropertyChanged;
				Page = null;
			}
			base.Dispose(disposing);
		}

		void PagePropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
		{
			if (e.PropertyName == NavigationPage.HasNavigationBarProperty.PropertyName
				|| e.PropertyName == Page.TitleProperty.PropertyName
				|| e.PropertyName == NavigationPage.HasBackButtonProperty.PropertyName)
				Platform.NativeToolbarTracker.UpdateToolBar();
		}

		public string Identifier { get; set; }

		public Page Page { get; private set; }
	}
}