Ooui-tws-port/Ooui.Forms/PageExtensions.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2017-11-09 06:21:05 +00:00
using System;
2017-11-09 07:57:04 +00:00
using Xamarin.Forms;
2017-11-09 07:12:59 +00:00
2017-11-09 07:57:04 +00:00
namespace Xamarin.Forms
2017-11-09 06:21:05 +00:00
{
2017-11-09 21:03:56 +00:00
public static class PageExtensions
{
public static void Publish (this Xamarin.Forms.Page page, string path)
{
Ooui.UI.Publish (path, () => page.CreateElement ());
}
2017-11-09 07:12:59 +00:00
2017-11-09 21:03:56 +00:00
public static void PublishShared (this Xamarin.Forms.Page page, string path)
{
var lazyPage = new Lazy<Ooui.Element> ((() => page.CreateElement ()), true);
Ooui.UI.Publish (path, () => lazyPage.Value);
}
2017-11-09 07:12:59 +00:00
2017-11-09 21:03:56 +00:00
public static Ooui.Element CreateElement (this Xamarin.Forms.Page page)
{
if (!Xamarin.Forms.Forms.IsInitialized)
throw new InvalidOperationException ("call Forms.Init() before this");
2017-11-09 07:12:59 +00:00
2017-11-09 21:03:56 +00:00
if (!(page.RealParent is Application)) {
var app = new DefaultApplication ();
app.MainPage = page;
}
2017-11-09 07:57:04 +00:00
2017-11-09 21:03:56 +00:00
var result = new Ooui.Forms.Platform ();
result.SetPage (page);
return result.Element;
}
2017-11-09 07:57:04 +00:00
2017-11-09 21:03:56 +00:00
class DefaultApplication : Application
{
}
}
2017-11-09 06:21:05 +00:00
}