Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
76 lines (56 sloc) 1.76 KB
{"exec-mode":"default","platform":"iOS","uti":"com.xamarin.workbook","packages":[{"id":"Xamarin.Forms","version":"2.2.0.31"}]}

Xamarin.Forms Workbook test

A little hack to demo Xamarin.Forms on iOS with Workbooks...

  1. Start by importing the Nugets for Xamarin.Forms and the iOS Platform Renderers
#r "Xamarin.Forms.Platform.iOS"
#r "Xamarin.Forms.Core"
#r "Xamarin.Forms.Xaml"
#r "Xamarin.Forms.Platform"
  1. We need using statements too:
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
  1. Set up a simple page with an exposed property for us to edit:
public class MyPage : ContentPage 
{
	public Label Hi {get;set;}
	public MyPage () 
	{
		Title = "A test";
		
		Hi = new Label {Text = "Hello, Workbooks"};
		
		var s = new StackLayout{Children = {Hi}};
		
		Content = s;
	}
}
  1. Ok great - but we can’t see anything! Oh, we need to bootstrap the Xamarin.Forms app object too:
public class App : Application
{
	public MyPage MP {get;set;}
	public App ()
	{
		MP = new MyPage();
		MainPage = new NavigationPage (MP);
	}
}
  1. Now - here comes the “hack” - sneakily bypass requiring the FormsApplicationDelegate subclass (thank goodness it’s open source) and just set the iOS root view controller directly:
Xamarin.Forms.Forms.Init();
var a = new App();
KeyWindow.RootViewController = a.MainPage.CreateViewController();

⚠️ *YMMV with some Xamarin.Forms features when hacking forms to start-up like this - *
BE WARNED!

  1. To prove it works, modify properties and hit <return>:
a.MP.Title = "Another test";
a.MP.Hi.Text = "Goodbye";