summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.MacOS/Extensions/PageExtensions.cs
blob: 24c9a52734bff10aaed1b3de2c96277ba32d134b (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
´╗┐using System;
using AppKit;

namespace Xamarin.Forms.Platform.MacOS
{
	public static class PageExtensions
	{
		public static NSViewController CreateViewController(this Page view)
		{
			if (!Forms.IsInitialized)
				throw new InvalidOperationException("call Forms.Init() before this");

			if (!(view.RealParent is Application))
			{
				Application app = new DefaultApplication();
				app.MainPage = view;
			}

			var result = new Platform();
			result.SetPage(view);
			return result.ViewController;
		}

		class DefaultApplication : Application
		{
		}
	}
}