神刀安全网

Craig Dunn: Xamarin.Forms Workbooks

As explained in thelast post, it’s easy to add Nuget packages to Xamarin Workbooks . My immediate reaction to this news was "I want to use Xamarin.Forms!" Unfortunately it’s not immediately obvious how to get Xamarin.Forms into a Workbook… so here are the steps (for an iOS Workbook):

1. Add the Xamarin.Forms nuget (and reference the platform)

When you add the Xamarin.Forms Nuget, four assemblies will be referenced (including the iOS Platform assembly for Xamarin.Forms). The using statements need to be added too – don’t forget to add the Xamarin.Forms.Platform.iOS namespace:

Craig Dunn: Xamarin.Forms Workbooks

2. Create a Page and App as usual

In both classes it’s a good idea to create public properties for elements you want to manipulate in the workbook.

Craig Dunn: Xamarin.Forms Workbooks

This allows those controls to be referenced later in the workbook…

3. Hack the FormsAppDelegate

The biggest hurdle to getting Xamarin.Forms to run is that in a normal iOS app, the AppDelegate must be a subclass of FormsApplicationDelegate to wire up various bits of Xamarin.Forms. Peeking into the open-source , the key thing we need to do is set the RootViewController … the following code does the initialization we need to get a Workbook running:

Craig Dunn: Xamarin.Forms Workbooks

WARNING: obviously this approach misses some of the other code implemented in  FormsApplicationDelegate so some things might not work as expected. This is a bit of a hack :)

4. Run It

The public properties on the App and Page classes mean the workbook can manipulate those elements to demonstrate various Xamarin.Forms capabilities.

Craig Dunn: Xamarin.Forms Workbooks

Try it out with the  WorkbookFormsTest workbook:

Craig Dunn: Xamarin.Forms Workbooks

Check out the more complex ListView1 workbook too:

Craig Dunn: Xamarin.Forms Workbooks

p.s. the irony of included screenshots of code is not lost on me – but hey, it’s actually a good reason to download and us Xamarin Workbooks

to try these samples out 😀

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Craig Dunn: Xamarin.Forms Workbooks

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址